Extending Rails for Real World App Development

Extending Rails for Real World App Development

Rails Developers Meetup 2019 の講演「毎日の開発に役立つRailsプラグインづくりの秘訣」のスライド https://railsdm.github.io/ #RailsDM

76a777ff80f30bd3b390e275cce625bc?s=128

Akira Matsuda

March 22, 2019
Tweet

Transcript

  1. ຖ೔ͷ։ൃʹ໾ཱͭ RailsϓϥάΠϯ
 ͮ͘Γͷൿ݃ @a_matsuda

  2. ࠷ॳʹ͓஌Βͤ 3ͭ

  3. None
  4. RubyKaigiͷLTͷϓϩϙʔβϧड෇தʂ ໌ޙ೔·Ͱʂ

  5. RejectKaigiͷϓϩϙʔβϧ΋ืूதʂ ࠓ݄͍ͬͺ͍ʂ

  6. None
  7. Asakusa.rb Ֆݟ΍Γ·͢ʂ
 དྷिͷ౔༵೔ʂ

  8. ࠓ೔࿩͢͜ͱ ൺֱత࠷ۙ࡞ͬͨgemͷ࿩ ͋Δ͍͸ ਓ͸ͳͥgemΛ࡞Δͷ͔

  9. ࠓ೔࿩͢͜ͱ ͦΕ͔Βɺ

  10. ࠓ೔࿩͢͜ͱ ςετίʔυ͕։ൃΛ
 υϥΠϒ͢Δ࿩

  11. ࠓ೔࿩͞ͳ͍͜ͱ action_args active_decorator database_rewinder gem_src i18n_generators jb kaminari motorhead rfd

    stateful_enum string_template traceroute ...
  12. Question

  13. Կ͔࣮༻ϨϕϧͷgemΛࣗ෼Ͱ࡞ͬͯ
 ϦϦʔεͯ͠Έͨ͜ͱ͕͋Δਓ ✋

  14. ͍·खΛڍ͛ͯͳ͍ਓͨͪʹ
 ݴ͍͍ͨ

  15. Why Don't You Create
 Your Own Gems?

  16. ͳͥgemΛ࡞Βͳ͍ͷ͔ʁ ·ͨ͸ɺਓ͸ͳͥgemΛ
 ࡞Δͷ͔ʁ

  17. ๻ͷ৔߹͸ɺ΄΅100%
 ʮݱ৔ͷ໰୊Λղܾ͢ΔͨΊʯ

  18. Case #1

  19. ݱ৔ͷ໰୊ ςετ͸΋ͪΖΜॻ͔ͳͬͪ͘Ό͋
 ͍͚ͳ͍ Ͱ΋E2Eςετॻ͘ͷΊΜͲ͍ ߲໨͕૿͖͑ͯͨΓ͢ΔͱͭΒ͍

  20. ͖͔͚ͬ

  21. ͖͔͚ͬ

  22. ͖͔͚ͬ ৽نϓϩδΣΫτΛ࢝ΊΔʹ͋ͨͬͯɺ E2Eςετͱ͔͋Μ·Γॻ͍ͨ͜ͱ
 ͳ͍͍ͬͯ͏ए͍ϝϯόʔ΋ډͨ ୭Ͱ΋ςετ͕αΫαΫͬͱॻ͚Δͱ
 ͍͍ͳ͊ɺͱࢥͬͯ࡞ͬͯΈͨ

  23. heavens_door

  24. ͜ͷgemΛ࡞Δʹ͋ͨͬͯ
 ؾΛ͚ͭͨ͜ͱ ͱʹ͔͘୯ػೳʹ͢Δ

  25. ϒϥ΢βͷૢ࡞Λه࿥ͯ͠Capybaraͷ γφϦΦΛ࡞ΔϓϥάΠϯ ͘͢͝௚ײత

  26. ࢖͍ํ͸READMEʹషͬͨΞχϝgifΛ ݟΕ͹͙͢Θ͔ΔͷͰɺઆ໌͸লུ

  27. heavens_door https:/ /github.com/ amatsuda/heavens_door

  28. ͱ͜ΖͰɺ

  29. ͝هԱͷํ΋Կ໊͔͍Βͬ͠Όͬͨ Α͏Ͱ͕͢ɺ

  30. ࣮͸ɺ͜ͷίϯηϓτ͸શવ
 ৽͘͠ͳͯ͘ɺ

  31. ͸Δ͔ੲʹhocus_pocusͰ
 Ұ౓΍ͬͨ͜ͱͷম͖௚͠

  32. Case #2

  33. hocus_pocus ྺ࢙ͷڱؒʹຒ΋ΕͨΦʔύʔπ ௒ଟػೳͳϒϥ΢β಺౷߹։ൃ
 ؀ڥΈ͍ͨͳ΋ͷΛ໨ࢦͨ͠

  34. ͜Ε͸ɺԿ͔ղܾ͍ͨ͠໰୊͕͋ͬͨͱ͍͏ΑΓ͸ɺ ࡞Εͦ͏ͳؾ͕͔ͨ͠Β࡞Γ࢝ΊͯΈͨɺͱ͍͏ײ͡

  35. hocus_pocusͷߏ଄ main_appʹmount͞Εͨhocus_pocus
 Τϯδϯ͕͞Βʹ4ͭͷαϒmountable engine Λmountͯ͠Δͱ͍͏ແବʹෳࡶͳߏ੒ ౰࣌ੈքॳͩͬͨ͸ͣͩ͠ɺͨͿΜະͩʹ
 ͦΜͳengine͸ଞʹແ͍ͷͰ͸ͳ͍͔

  36. hocus_pocusͷࢥ૝ "resource missing" driven development ϖʔδ಺ʹWikiNameΛॻ͍ͨΒɺ
 ৽͍͠Wikiϖʔδ΁ͷϦϯΫʹͳͬͯ͘
 ͋ͷײ͡

  37. ͱ͔2019೥ʹݴͬͯ΋ɺ͋Μ·Γ
 ఻ΘΒͳͦ͏ͳͷͰ

  38. ͓Αͦ7೥ͿΓʹDEMO

  39. 7೥લ

  40. hocus_pocus https:/ /github.com/ amatsuda/hocus_pocus

  41. 9೥લʹ࡞Γ࢝Ίͨ΍ͭ ·ͬͨ͘ྲྀߦΒͳ͔ͬͨ ͱ͍͏͔׬੒͢Β͠ͳ͔ͬͨ

  42. hocus_pocusͷͦͷޙ ૖େͳߏ૝͸৭ʑ͚͋ͬͨͲɺ
 ΍Δؾ͕࣋ଓͤͣʹdiscon

  43. ΋͏ͪΐ͍׬੒౓͕ߴ͘ͳͬͨΒυΩϡϝϯτ
 ͱ͔΋ͪΌΜͱॻ͜͏ɺͱࢥͬͯͨ ͚ͲɺͦΜͳ೔͸དྷͳ͔ͬͨ

  44. ͔͜͜Βಘͨڭ܇ ݱ৔ͷ໰୊υϦϒϯ͡Όͳ͍झຯͷ։ൃ͸Ϟνϕʔ γϣϯͷҡ͕࣋೉͍͠ খ͘͞࡞ͬͯૣΊʹϦϦʔεɺ͕΍ͬͺΓେࣄ υΩϡϝϯςʔγϣϯେࣄ ͦ΋ͦ΋࢖͍ํ͕೉͗͢͠Δπʔϧ͸࢖ͬͯ΋Β͑
 ͳ͍

  45. খ͘͞࡞ͬͯૣΊʹϦϦʔεɺ
 ͕΍ͬͺΓେࣄ ࢥ͍͍ͭͨΞΠσΞ͸͙͢ʹ࣮૷ Ͱ͖ΔαΠζ͡Όͳ͍ͱɺͳΜ ͔ͩͬͨ๨ΕΔ

  46. υΩϡϝϯςʔγϣϯ େ࡞ͳgem͸υΩϡϝϯτΛॻ͘
 োน͕ߴ͍ ͦ͏͍͏ҙຯͰ΋ػೳ͸গͳ͍
 ΄͏͕ྑ͍

  47. ͦ΋ͦ΋࢖͍ํ͕೉͗͢͠Δπʔϧ ͸࢖ͬͯ΋Β͑ͳ͍ ίϯηϓτ͕ಛघͩͬͨΓ͢Δ ͱɺ఻ΘΒͣʹऴΘΔ

  48. hocus_pocusͰͷࣦഊΛ׆͔ͯ͠ heavens_doorͰ΍ͬͯΈͨ͜ͱ

  49. Ξχϝgif

  50. Ξχϝgif͍͢͝

  51. ʮݴ༿ʯͰͳ͘ʮ৺ʯͰ
 ཧղͰ͖Δʂ

  52. Ͱ΋ɺ͜ͷϝιου͕ద༻Ͱ͖ΔRuby ͷϥΠϒϥϦ͸ͦΜͳʹଟ͘ͳ͍͔΋ʁ ࣮ࡍɺࣗ෼͕࡞ͬͨଞͷϥΠϒϥϦͰ͜ͷϝιου
 ͕׆༻Ͱ͖Δ͔Ͳ͏͔ߟ͑ͯΈ͚ͨͲɺ࣮ࡍͳ͔ͳ͔
 νϟϯε͸ͳͦ͞͏ ͯͳΘ͚ͰɺRubyͷϥΠϒϥϦΑΓ΋JSͱ͔ͷ
 ϥΠϒϥϦͷํ͕⭐ΛूΊ΍ͦ͢͏ɺ͍ͬͯ͏࿩͸
 ͋ΔΜͩΑͳ͊

  53. ͱ͜ΖͰɺ͜ͷϒϥ΢β಺ͰΞϓϦ Λ։ൃ͍ͯ͘͠ͱ͍͏ίϯηϓτ 2019೥ʹͳͬͯɺ͋ͷ”conductor”͕ ੝Γ্͕ΓΛݟͤΔػӡ ͜Ε͔Β·ͩ·ͩՄೳੑͷ͋Δ෼໺
 ͳͷͰ͸

  54. ͦ͜Ͱɺϒϥ΢βͰԿ͔͢Δ΍ͭΛ
 ΋͏1ͭ

  55. Case #3

  56. ݱ৔ͷ໰୊ ERਤ͕ݟ͍ͨʂ

  57. ݱ৔ͰERਤݟ͍ͨͰ͢ΑͶʁ ͨͱ͑͹ͪΐͬͱΤϯλʔϓϥΠ ζͬΆ͍Ҋ݅ʹ్த͔Βࢀըͨ͠ ࣌ͱ͔

  58. ͦ͜Ͱerd RailsΞϓϦʹmountͯ͠࢖͏ engine ਌ΞϓϦͷERਤΛϒϥ΢β಺ʹදࣔ ͍ͭͰʹૢ࡞

  59. ૢ࡞ʁ create tableͱ͔alter tableͱ͔ migrationΛ࡞੒ɺ࣮ߦ migrationͷॻ͖ํΛ֮͑ΒΕͳ͍/ࢥ͍ग़ͤͳ͍
 ਓʹ͓͢͢Ί migration ͕ʮݴ༿ʯͰͳ͘ʮ৺ʯͰ(ry

  60. DEMO

  61. Status of erd ͥΜͥΜະ׬੒ UI͕͍Ζ͍ΖϏϛϣʔ ΋ͬͱϒϥογϡΞοϓ͍ͨ͠ؾ࣋ͪ͸͋Δ͚ͲJSॻ͘ͷ
 ͠ΜͲ͍ coffeeͰࡶʹॻ͍ͯdecafͨ͠ίʔυ͕΋͸΍ϝϯςෆೳϨϕϧ ୭͔JS͕ಘҙͳํɺॿ͚͍ͯͩ͘͞ʂʂʂʂ(੾࣮)

  62. erd https:/ /github.com/ amatsuda/erd

  63. ͯ͞ɺ࿩͸มΘͬͯɺϒϥ΢β্ͰΤϯϓϥ
 ͬΆ͍ਤΛදࣔ͢ΔengineΛ΋͏1ͭ

  64. Case #4

  65. ݱ৔ͷ໰୊ ࠓ౓͸ը໘ભҠਤ͕ݟ͍ͨʂ

  66. ͜Ε΋ݱ৔ͷ੾࣮ͳ໰୊ routes.rb ΛݟΕ͹Ϧιʔεͷ
 Ұཡ͸Θ͔Δ Ͱ΋ͭͳ͕Γ͸ݟ͑ͳ͍

  67. ΍ͬͺը໘ભҠਤ

  68. ίϯηϓτ ը໘ભҠਤͬͯੲ͸ΈΜͳखඳ͖ ͯͨ͠΋ͷ͚ͩͲɺߟ͑ͯΈͨΒ ͜Εͬͯੜ੒Ͱ͖ΔΜ͡Όͳ͍ ͔ʁ

  69. roundabout

  70. DEMO

  71. ΍ͬͯΔ͜ͱ E2Eςετ಺Ͱ࣮ߦ͞Εͨը໘
 ભҠΛશͯه࿥ ͦͷ݁ՌΛਤࣔ

  72. ͜Ε͕ԿΛද͍ͯ͠Δͷ͔ ࣮ࡍʹ࣮૷͞Εͯͯςετ͞Εͯ ͍Δը໘ભҠΛه࿥ ͨͩͷ routes.rb ͷਤࣔͱ͸ҧ͏

  73. ςετ͕ͪΌΜͱॻ͔Ε͍ͯΔ͔ͷ ֬ೝʹͳΔ ͋ΔҙຯΧόϨοδͷදࣔͷҰछ ͷΑ͏ͳ΋ͷͱݴ͑Δ͔΋

  74. ͜ͷgemͷΑ͞ ॻ͍ͨςετ͕ܗΛม͑ͨࢿ࢈ʹ ͳΔͷ͕Α͍

  75. ࣍͸΋͏1ͭɺςετࢿ࢈Λ׆͔͢΍ͭ Λ͝঺հ

  76. Case #5

  77. ݱ৔ͷ໰୊ RailsΞοϓάϨʔυͰσάϨ
 ͨ͘͠ͳ͍

  78. still_life

  79. still_lifeͰͰ͖Δ͜ͱ ςετΛ૸Βͤͨࡍʹɺςετத ʹrender͞ΕͨHTMLΛશ෦
 ϑΝΠϧʹॻ͖ग़͢

  80. ͍͢͝ྗٕͳϓϥάΠϯ

  81. ໨త ΞϓϦέʔγϣϯίʔυͷॻ͖׵͑
 લޙʹɺϢʔβʔʹಧ͚͍ͯΔ΋ͷ ͕มԽ͍ͯ͠ͳ͍͜ͱΛ֬ೝͰ͖Δ

  82. ಛ௃ ը໘Λ౿ΜͰճΔ͚ͩͰྑͯ͘ɺ ΞαʔγϣϯΛॻ͔ͳͯ͘ྑ͍
 ͷͰָνϯ

  83. Ͳ͏͍͏࣌ʹ࢖͏ͷ͔ ಛʹRailsͷΞοϓάϨʔυ͕
 ૝ఆ༻్ Ұൠతʹ֤छϦϑΝΫλϦϯάͷ ࢧԉʹͳΔ͸ͣ

  84. ͦ΋ͦ΋ͷݩωλ 2011೥ʹɺΫοΫύουͷRails ͷόʔδϣϯΛ্͛Δ࣌ʹηίϯ ͞Μ͕ॻ͖ࣺͯͨεΫϦϓτ

  85. https:/ /speakerdeck.com/a_matsuda/the-recipe- for-the-worlds-largest-rails-monolith?slide=129

  86. cookpad

  87. ·͞ʹݱ৔ͷ໰୊Λత֬ʹղܾ͢Δ ৬ਓٕ

  88. gemԽʹ͋ͨͬͯɺҎԼͷશ໘αϙʔτ
 Λ௥Ճ Capybara 3 RSpec 3 test-unit minitest

  89. օ͞Μͷݱ৔Ͱ΋΋͏͖͡ Rails 5.2 -> 6.0 ͷΞοϓάϨʔυۀ͕࢝·Δͱࢥ͍·͕͢ɺ ͔ͳΓ༗༻͔΋͠Εͳ͍ͷͰɺ
 Ͳ͏ͧ͝׆༻͍ͩ͘͞

  90. ͱ͜ΖͰɺ͜ͷϥΠϒϥϦͷओͳೳྗ͸
 ΞϓϦΛ͜͡։͚ͯಈ࡞Λه࿥͢Δελϯυ ͜ͷೳྗͬͯɺ͜Εͦ͜
 "heavens_door" ͡Ό͋Ͷ͔͑ʂ

  91. ͱࢥ͚ͬͨͲɺͦͷ໊લͷgem͸طʹ औΒΕͯ͠·͍ͬͯͨͷͰ͋ͬͨ

  92. ໊લॏཁ gemͷ໊લ͚ͭΔͷ೉͍͠……

  93. ͜ΕΛ8೥ӽ͠ͰgemԽ͖͔͚ͨͬ͠ ࣗ࡞ςϯϓϨʔτΤϯδϯͷಈ࡞ݕূͷ ͨΊʹཉ͘͠ͳͬͨ ๭ΠϯλʔωοτՈܭ฽ͷRailsΞοϓ άϨʔυͷࡍʹ͜ΕͷଘࡏΛࢥ͍ग़ͨ͠

  94. Money Forward

  95. ʮࣗ࡞ςϯϓϨʔτΤϯδϯʯ

  96. Case #6

  97. Himl

  98. Himl ͖͔͚ͬ͸ɺӬ࿨γεςϜϚωδ ϝϯτͰຖ݄΍ͬͯΔOSSύον ձ

  99. ͷ͋ͱͷҿΈձ

  100. Ӭ࿨γεςϜϚωδϝϯτ

  101. kamipo͞Μͷ۪ஒ kamipo: ձࣾͰHaml࢖ͬͯΔ͚ͲɺHaml ͱ͔Slimͱ͔จ๏͕Ṗ֮͗ͯ͑͢ΒΕ΁Μ ΘɻERBͰྑ͘ͳ͍ʁ me: ͍΍ʔɺHaml௒͍͍ͬ͢ΑɻERBʹ໭ Δͱ͔ϜϦϜϦɻ

  102. ͔͠͠ɺ͋ΒͨΊͯɺHamlͷྑͬͯ͞ ͳΜͩΖ͏ʁ ͔֬ʹɺ͋ͷه߸ͨͪΛۦ࢖ͨ͠จ๏ࣗମ ͸Hamlͷྑ͞ͷຊ࣭Ͱ͸ͳ͍͔΋ Hamlͷྑ͞͸ɺλάΛػց͕ดͯ͘͡ΕΔ ͓͔͛ͰɺίϯύΠϧ͞ΕͨHTML͕valid ͳ͜ͱ͕อূ͞ΕΔͱ͜Ζ

  103. ͡Ό͋ɺHamlͷྑ͞ΛERBʹ஫ೖͯ͠ ΍Ε͹ྑ͍ͷͰ͸ʁ

  104. Αͦ͞͏ɺ͔΋͠Εͳ͍

  105. ͷͰ࡞ͬͯΈͨ

  106. Himl https:/ /github.com/ amatsuda/himl

  107. ࠓճͷݱ৔͸… ਆాͷͱ͋Δډञ԰

  108. Himlͷ։ൃΛ௨ͯ͡Θ͔ͬͨ͜ͱ

  109. ډञ԰ͩͬͯݱ৔ͳΜ΍ʂ

  110. ·ͱΊ

  111. ਓ͸ͳͥgemΛ࡞Δͷ͔ʁ ໰୊Λղͨ͘Ί

  112. ໰୊͸ͨ͘͞Μݱ৔ʹస͕ͬͯΔ

  113. ͜͏͍͏໰୊ͷղ͖ํ΋͍͍Μ͡Ό ͳ͍Ͱ͠ΐ͏͔ʁ ͳ͔ͳָ͔͍͠Ͱ͢Α

  114. Why Don't You Create Your Own Gems? gem࡞Ζʔͥʂ

  115. end

  116. me Name: Akira Matsuda Twitter: @a_matsuda GitHub: amatsuda