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. ࣗݾ঺հ • ໊લ: ਖ਼ಙ ޼(aka: ਆ଎) • ձࣾ: - •

    GitHub: @sinsoku (ը૾ӈ্) • Twitter: @sinsoku_listy (ը૾ӈԼ) • ޷͖ͳݴޠ: Rust • Railsྺ: 8೥͘Β͍ 2
  2. RBSಋೖͷํ਑ • *.rbs ͸ࣗಈੜ੒͢Δ • rbs collection • rbs prototype

    • sord1 ʢYARD -> rbsʣ • gemͷෆ଍ͯ͠Δܕఆٛ͸࠷খݶ͚ͩ༻ҙ 1 https://github.com/AaronC81/sord 6
  3. Α͋͘ΔYARDͷྫ class User # @param item [Item] ΞΠςϜ # @param

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

    amount [Integer] ਺ྔ # @param coupon [Coupon] Ϋʔϙϯ # @return [Boolean] ߪೖͷ੒ޭ/ࣦഊ def buy(item, amount, coupon = nil); end end 14
  5. ͜͏ͳΔ class User # @!sig (Item, Integer, ?Coupon) -> bool

    def buy(item, amount, coupon = nil); end end 15
  6. yard-sig • YARDϓϥάΠϯ • yard doc --plugin sig Ͱ࢖༻Մ3 •

    จ๏͸RBS Syntaxͱಉ͡ • ಺෦Ͱ @param ΍ @return ͳͲͷλάʹม׵ 3 .yardopts ʹ --plugin sig Λࢦఆ͢Δͱָ 16
  7. ໰୊ͷཁ໿ طଘϨίʔυ͕͋Δͱ͖ͷ create_association ͷڍಈ͕มΘΔɻ • v7.0.4: save(validate, INSERT) -> destroy(DELETE)

    • v7.0.5: destroy(DELETE) -> save(validate, INSERT) v7.0.4·Ͱ͸ผʑͷτϥϯβΫγϣϯͰɺόϦσʔγϣϯʹࣦഊ͠ ͯ΋طଘϨίʔυ͕࡟আ͞Ε͍ͯͨɻ 19
  8. Өڹ͕͋Δέʔε 1. Uniquness Validator4 2. UNIQ constraint 3. DBґଘͷCustom Validation

    • ྫ: ϨίʔυΛ࡞੒͔ͯ͠Β10෼Ҏ಺ 4 v7.0.4Ͱ΋όάͬͯΔͷͰɺجຊతʹ͸ؾʹ͢Δඞཁ͕ͳ͍͸ͣɻ 20