Upgrade to Pro — share decks privately, control downloads, hide ads and more …

YARD with RBS Syntax

YARD with RBS Syntax

【オフライン開催】Omotesando.rb #87
https://omotesandorb.connpass.com/event/287544/

Takumi Shotoku

July 06, 2023
Tweet

More Decks by Takumi Shotoku

Other Decks in Technology

Transcript

  1. YARD with RBS Syntax
    Omotesando.rb #87 2023/07/06
    1

    View full-size slide

  2. ࣗݾ঺հ
    • ໊લ: ਖ਼ಙ ޼(aka: ਆ଎)
    • ձࣾ: -
    • GitHub: @sinsoku (ը૾ӈ্)
    • Twitter: @sinsoku_listy (ը૾ӈԼ)
    • ޷͖ͳݴޠ: Rust
    • Railsྺ: 8೥͘Β͍
    2

    View full-size slide

  3. ઌ݄͔ΒRBSΛ࢖͍࢝Ί·ͨ͠
    3

    View full-size slide

  4. ͖͔͚ͬ: MedPeerͷϒϩά
    4

    View full-size slide

  5. ࣾ಺ͷ૯ҙ: ܕͷԸܙΛड͚͍ͨ
    ʢͨͩ͠ܕ͸ࣗ෼Ͱॻ͖ͨ͘͸ͳ͍ʣ
    5

    View full-size slide

  6. RBSಋೖͷํ਑
    • *.rbs ͸ࣗಈੜ੒͢Δ
    • rbs collection
    • rbs prototype
    • sord1 ʢYARD -> rbsʣ
    • gemͷෆ଍ͯ͠Δܕఆٛ͸࠷খݶ͚ͩ༻ҙ
    1 https://github.com/AaronC81/sord
    6

    View full-size slide

  7. ಋೖͷৄࡉ͸ׂѪʢͨͿΜϒϩάॻ͘ʣ
    7

    View full-size slide

  8. ͔͜͜Βຊ୊
    8

    View full-size slide

  9. Α͋͘ΔYARDͷྫ
    class User
    # @param item [Item] ΞΠςϜ
    # @param amount [Integer] ਺ྔ
    # @param coupon [Coupon] Ϋʔϙϯ
    # @return [Boolean] ߪೖͷ੒ޭ/ࣦഊ
    def buy(item, amount, coupon = nil); end
    end
    9

    View full-size slide

  10. ୭΋େͨ͠આ໌Λॻ͍͍ͯͳ͍
    10

    View full-size slide

  11. ීஈ͸ܕ͚ͩॻ͚͹े෼Ͱ͸ʁ 2
    2 େࣄͳ෦෼ʹ͸આ໌Λॻ͚͘ͲɺܕͱҾ਺໊Ͱे෼ͳέʔε΋ଟ͍ɻ
    11

    View full-size slide

  12. ͦΜͳgemΛ࡞Γ·ͨ͠
    12

    View full-size slide

  13. !
    yard-sig
    https://github.com/sinsoku/yard-sig
    13

    View full-size slide

  14. ͜Ε͕
    class User
    # @param item [Item] ΞΠςϜ
    # @param amount [Integer] ਺ྔ
    # @param coupon [Coupon] Ϋʔϙϯ
    # @return [Boolean] ߪೖͷ੒ޭ/ࣦഊ
    def buy(item, amount, coupon = nil); end
    end
    14

    View full-size slide

  15. ͜͏ͳΔ
    class User
    # @!sig (Item, Integer, ?Coupon) -> bool
    def buy(item, amount, coupon = nil); end
    end
    15

    View full-size slide

  16. yard-sig
    • YARDϓϥάΠϯ
    • yard doc --plugin sig Ͱ࢖༻Մ3
    • จ๏͸RBS Syntaxͱಉ͡
    • ಺෦Ͱ @param ΍ @return ͳͲͷλάʹม׵
    3 .yardopts ʹ --plugin sig Λࢦఆ͢Δͱָ
    16

    View full-size slide

  17. σϞʢϦϦʔε࡞ۀʣ
    17

    View full-size slide

  18. ͓·͚: Rails v7.0.5ͷ has_one ͕ਏ͍
    18

    View full-size slide

  19. ໰୊ͷཁ໿
    طଘϨίʔυ͕͋Δͱ͖ͷ create_association ͷڍಈ͕มΘΔɻ
    • v7.0.4: save(validate, INSERT) -> destroy(DELETE)
    • v7.0.5: destroy(DELETE) -> save(validate, INSERT)
    v7.0.4·Ͱ͸ผʑͷτϥϯβΫγϣϯͰɺόϦσʔγϣϯʹࣦഊ͠
    ͯ΋طଘϨίʔυ͕࡟আ͞Ε͍ͯͨɻ
    19

    View full-size slide

  20. Өڹ͕͋Δέʔε
    1. Uniquness Validator4
    2. UNIQ constraint
    3. DBґଘͷCustom Validation
    • ྫ: ϨίʔυΛ࡞੒͔ͯ͠Β10෼Ҏ಺
    4 v7.0.4Ͱ΋όάͬͯΔͷͰɺجຊతʹ͸ؾʹ͢Δඞཁ͕ͳ͍͸ͣɻ
    20

    View full-size slide

  21. rails/rails#48643
    21

    View full-size slide