Rails 6.0の気になった新機能 #shuuumai

Rails 6.0の気になった新機能 #shuuumai

『【シューマイ】Tech Lead Engineerから最新技術を学べ!Rails編×station』
https://shuuu-mai.connpass.com/event/146313/

B7bf4e80841a44f921665e88d874f2c3?s=128

Hiroaki Ninomiya

October 09, 2019
Tweet

Transcript

  1. Rails 6.0 ͷؾʹͳͬͨ৽ػೳ 2019/10/09 γϡʔϚΠRailsฤ Hiroaki Ninomiya a.k.a @treby006

  2. ࣗݾ঺հ • treby(ͱΕͼʔ) a.k.a Hiroaki Ninomiya • Reproגࣜձࣾ BizDevࣄۀ෦ •

    Solution Architect • BtoB SaaSاۀ • ৬ۀΤϯδχΞͷΩϟϦΞΛߟ͑Δɺʮ͖ͷ͜ΔΤϑΤϜʯ΍͍ͬͯ·͢ • Vue Fes Japan 2019 ίΞελοϑ(୆෩)
  3. ϙουΩϟετ

  4. Vue Fes Japan 2019(10/12)

  5. Agenda • ձࣾ঺հ • ࣮։ൃऀͱͯ͠Rails6ͷ͏ͪؾʹͳͬͨػೳΛ͝঺հʂ

  6. Reproגࣜձࣾ • 2014೥ઃཱͷελʔτΞοϓاۀ • https://repro.io/ • BtoB SaaS • ࣗࣾϓϩμΫτRepro

    SDKΛ։ൃ • ϞόΠϧΞϓϦͷ෼ੳɾϚʔέςΟϯά༻్ • ಛఆηάϝϯτʹ؆୯ʹϓογϡ௨஌͕ଧͯΔ • ݱࡏɺઈࢍٸ੒௕த
  7. Solution Architect • Bizdev -> ʮࣄۀ੒௕ΛՃ଎ͤ͞Δʯ࢓ࣄ • https://note.mu/saas_bizdev/n/ncd38d86262f4 • BizDevͷSolution

    Architect • ཁ݅ఆٛΛ͢ΔΑΓߋʹલ͔ΒೖΔ • ސ٬ͷཁٻཧղɺ࿈ܞީิπʔϧͱͷίϛϡχέʔγϣϯ • ࿈ܞͷ͋Δ΂͖ʹ͍ͭͯɺϩʔυϚοϓΛҾ͖ɺ࣮ߦ͢Δ • هࣄॻ͍ͨͷͰΑ͚Ε͹: https://tech.repro.io/entry/2019/08/21/174705
  8. ReproͷRails • Repro͸ൃදஈ֊Ͱ͸Rails 5.2 • Rails 6.0ʹ͢ΔPR͸ཱͬͯΔͷͰ΋͏·΋ͳ্͕͘ΔͩΖ͏

  9. Rails 6.0ͷ৽ػೳ https://railsguides.jp/60release_notes.html

  10. ಛʹݸਓతʹؾʹͳͬͨػೳ • Railties • Action Pack • Active Support

  11. rails routesग़ྗΛ֦ுϑΥʔϚοτ ͰදࣔͰ͖Δػೳ • rails routes --expanded ͱॻ͘ͱීஈͷςʔϒϧϑΥʔϚοτͰͳ ͘ৄࡉͳද͕ࣔͳ͞ΕΔ •

    େن໛ΞϓϦέʔγϣϯͷRoutesͷߜΓࠐΈ͕Ͱ͖Δ΋ͷ͸ͳ ͍ͷ͔ • ࣮͸ -g Φϓγϣϯ͕͋ͬͨɺ஌Βͳ͔ͬͨ • https://github.com/rails/rails/pull/23225 ɺ2016೥ Rails 5 ͔Β
  12. ͢΂ͯͷenum஋ʹ͍ͭͯωΨςΟϒ είʔϓΛ௥Ճ • https://github.com/rails/rails/pull/35381 • λΠτϧ͚ͩͰ͸Կͷ͜ͱ͔෼͔Βͳ͍Ͱ͕͢ class Post < ActiveRecord::Base

    enum status: [:drafted, :active, :trashed] end • Post.not_drafted Έ͍ͨͳࢦఆ͕Ͱ͖ΔΑ͏ʹͳΔ • ݸผʹscope੾͍ͬͯͨͷ͕ෆཁʹͳΔ • ͦ΋ͦ΋enum͕޷͖͔Ͳ͏͔ͱ͍͏ͷ͸͋Γ·͕͢ɺɺɺ
  13. ActiveRecord.enumͰੜ੒͞Εͨε ίʔϓΛແޮʹ͢ΔػೳΛ௥Ճ • https://github.com/rails/rails/pull/34605 • ಠࣗͰείʔϓ੾͍ͬͯͨ৔߹ͱ͔࢖͑ͦ͏ • ͦ΋ͦ΋enum͕޷͖͔(ry

  14. before? ϝιουͱ after? ϝιουΛҎԼʹ௥Ճ Date ɺDateTime ɺTime ɺTimeWithZone • https://github.com/rails/rails/pull/32185

    • ࣌ؒൺֱܥ • :< , :> ͷൺֱͳͷ͚ͩͲ
  15. ҰׅINSERTΛߦ͏ insert_all / insert_all! / upsert_all ϝιουΛ ௥Ճ • https://github.com/rails/rails/pull/35077

    • ActiveRecord#insert_all • ΄͔ͬͨ͠΍ͭ
  16. ActiveRecord::Relation#annotate Λ௥Ճ: ActiveRecord::RelationΫΤ ϦʹSQLίϝϯτΛ௥Ճ͢Δ • annotate_models ͱ͸ผ෺ • ΞϓϦέʔγϣϯίʔυͷ೚ҙͷ৔ॴͰίϝϯτΛૠೖ͢Δ͜ͱ ͕Ͱ͖Δ

    • க͠ํͳ͘ൃߦ͍ͯ͠ΔΫΤϦͱ͔ɺେن໛ͳΞϓϦέʔγϣϯ Ͱ࢓ࠐΉΑ͏ʹ͓ͯ͘͠ͱௐ͕ࠪ͸͔ͲΓͦ͏
  17. ஍ຯʹخ͍͠ / ࢖͑ͦ͏ͳ͋Ε΍͜Ε΍ • Truncateͷαϙʔτ • https://github.com/rails/rails/pull/34779 • Ruby 2.6Ͱಋೖ͞ΕͨΤϯυϨεrangeΛ#whereͰαϙʔτ

    • https://github.com/rails/rails/pull/34779 • #inspectͷݸਓ৘ใσʔλΛϑΟϧλͰআ֎͢ΔػೳΛ௥Ճ • https://github.com/rails/rails/pull/34208
  18. ·ͱΊ • Rails6.0ؾʹͳͬͨػೳͱ࣮ࡍͷmigrateͷࣄྫΛ঺հ • Railsී௨ʹॻ͚ΔΑ͏ʹͳͬͨɺͱࢥͬͯ΋ͬ͘͡Γ Changelog΍PRݟͯΈΔͱൃݟ͕͋ͬͯ໘ന͍ • Rails 6.0ʹ͔ͯ͠Β࢖͍͍ͨػೳ͸͋Γ·͔ͨ͠ʁ •

    ActiveRecord , ActiveSupport पΓ͕๛࡞Ͱָͦ͠͏