Extending Rails for Real World App Development
by
Akira Matsuda
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
ຖͷ։ൃʹཱͭ RailsϓϥάΠϯ ͮ͘Γͷൿ݃ @a_matsuda
Slide 2
Slide 2 text
࠷ॳʹ͓Βͤ 3ͭ
Slide 3
Slide 3 text
No content
Slide 4
Slide 4 text
RubyKaigiͷLTͷϓϩϙʔβϧडதʂ ໌ޙ·Ͱʂ
Slide 5
Slide 5 text
RejectKaigiͷϓϩϙʔβϧืूதʂ ࠓ݄͍ͬͺ͍ʂ
Slide 6
Slide 6 text
No content
Slide 7
Slide 7 text
Asakusa.rb ՖݟΓ·͢ʂ དྷिͷ༵ʂ
Slide 8
Slide 8 text
ࠓ͢͜ͱ ൺֱత࠷ۙ࡞ͬͨgemͷ ͋Δ͍ ਓͳͥgemΛ࡞Δͷ͔
Slide 9
Slide 9 text
ࠓ͢͜ͱ ͦΕ͔Βɺ
Slide 10
Slide 10 text
ࠓ͢͜ͱ ςετίʔυ͕։ൃΛ υϥΠϒ͢Δ
Slide 11
Slide 11 text
ࠓ͞ͳ͍͜ͱ action_args active_decorator database_rewinder gem_src i18n_generators jb kaminari motorhead rfd stateful_enum string_template traceroute ...
Slide 12
Slide 12 text
Question
Slide 13
Slide 13 text
Կ͔࣮༻ϨϕϧͷgemΛࣗͰ࡞ͬͯ ϦϦʔεͯ͠Έͨ͜ͱ͕͋Δਓ ✋
Slide 14
Slide 14 text
͍·खΛڍ͛ͯͳ͍ਓͨͪʹ ݴ͍͍ͨ
Slide 15
Slide 15 text
Why Don't You Create Your Own Gems?
Slide 16
Slide 16 text
ͳͥgemΛ࡞Βͳ͍ͷ͔ʁ ·ͨɺਓͳͥgemΛ ࡞Δͷ͔ʁ
Slide 17
Slide 17 text
ͷ߹ɺ΄΅100% ʮݱͷΛղܾ͢ΔͨΊʯ
Slide 18
Slide 18 text
Case #1
Slide 19
Slide 19 text
ݱͷ ςετͪΖΜॻ͔ͳͬͪ͘Ό͋ ͍͚ͳ͍ ͰE2Eςετॻ͘ͷΊΜͲ͍ ߲͕૿͖͑ͯͨΓ͢ΔͱͭΒ͍
Slide 20
Slide 20 text
͖͔͚ͬ
Slide 21
Slide 21 text
͖͔͚ͬ
Slide 22
Slide 22 text
͖͔͚ͬ ৽نϓϩδΣΫτΛ࢝ΊΔʹ͋ͨͬͯɺ E2Eςετͱ͔͋Μ·Γॻ͍ͨ͜ͱ ͳ͍͍ͬͯ͏ए͍ϝϯόʔډͨ ୭Ͱςετ͕αΫαΫͬͱॻ͚Δͱ ͍͍ͳ͊ɺͱࢥͬͯ࡞ͬͯΈͨ
Slide 23
Slide 23 text
heavens_door
Slide 24
Slide 24 text
͜ͷgemΛ࡞Δʹ͋ͨͬͯ ؾΛ͚ͭͨ͜ͱ ͱʹ͔͘୯ػೳʹ͢Δ
Slide 25
Slide 25 text
ϒϥβͷૢ࡞Λهͯ͠Capybaraͷ γφϦΦΛ࡞ΔϓϥάΠϯ ͘͢͝ײత
Slide 26
Slide 26 text
͍ํREADMEʹషͬͨΞχϝgifΛ ݟΕ͙͢Θ͔ΔͷͰɺઆ໌লུ
Slide 27
Slide 27 text
heavens_door https:/ /github.com/ amatsuda/heavens_door
Slide 28
Slide 28 text
ͱ͜ΖͰɺ
Slide 29
Slide 29 text
͝هԱͷํԿ໊͔͍Βͬ͠Όͬͨ Α͏Ͱ͕͢ɺ
Slide 30
Slide 30 text
࣮ɺ͜ͷίϯηϓτશવ ৽͘͠ͳͯ͘ɺ
Slide 31
Slide 31 text
Δ͔ੲʹhocus_pocusͰ Ұͬͨ͜ͱͷম͖͠
Slide 32
Slide 32 text
Case #2
Slide 33
Slide 33 text
hocus_pocus ྺ࢙ͷڱؒʹຒΕͨΦʔύʔπ ଟػೳͳϒϥβ౷߹։ൃ ڥΈ͍ͨͳͷΛࢦͨ͠
Slide 34
Slide 34 text
͜ΕɺԿ͔ղܾ͍͕ͨ͋ͬͨ͠ͱ͍͏ΑΓɺ ࡞Εͦ͏ͳؾ͕͔ͨ͠Β࡞Γ࢝ΊͯΈͨɺͱ͍͏ײ͡
Slide 35
Slide 35 text
hocus_pocusͷߏ main_appʹmount͞Εͨhocus_pocus Τϯδϯ͕͞Βʹ4ͭͷαϒmountable engine Λmountͯ͠Δͱ͍͏ແବʹෳࡶͳߏ ࣌ੈքॳͩͬͨͣͩ͠ɺͨͿΜະͩʹ ͦΜͳengineଞʹແ͍ͷͰͳ͍͔
Slide 36
Slide 36 text
hocus_pocusͷࢥ "resource missing" driven development ϖʔδʹWikiNameΛॻ͍ͨΒɺ ৽͍͠WikiϖʔδͷϦϯΫʹͳͬͯ͘ ͋ͷײ͡
Slide 37
Slide 37 text
ͱ͔2019ʹݴͬͯɺ͋Μ·Γ ΘΒͳͦ͏ͳͷͰ
Slide 38
Slide 38 text
͓Αͦ7ͿΓʹDEMO
Slide 39
Slide 39 text
7લ
Slide 40
Slide 40 text
hocus_pocus https:/ /github.com/ amatsuda/hocus_pocus
Slide 41
Slide 41 text
9લʹ࡞Γ࢝Ίͨͭ ·ͬͨ͘ྲྀߦΒͳ͔ͬͨ ͱ͍͏͔͢Β͠ͳ͔ͬͨ
Slide 42
Slide 42 text
hocus_pocusͷͦͷޙ େͳߏ৭ʑ͚͋ͬͨͲɺ Δؾ͕࣋ଓͤͣʹdiscon
Slide 43
Slide 43 text
͏ͪΐ͍͕ߴ͘ͳͬͨΒυΩϡϝϯτ ͱ͔ͪΌΜͱॻ͜͏ɺͱࢥͬͯͨ ͚ͲɺͦΜͳདྷͳ͔ͬͨ
Slide 44
Slide 44 text
͔͜͜Βಘͨڭ܇ ݱͷυϦϒϯ͡Όͳ͍झຯͷ։ൃϞνϕʔ γϣϯͷҡ͕͍࣋͠ খ͘͞࡞ͬͯૣΊʹϦϦʔεɺ͕ͬͺΓେࣄ υΩϡϝϯςʔγϣϯେࣄ ͍ͦͦํ͕͗͢͠ΔπʔϧͬͯΒ͑ ͳ͍
Slide 45
Slide 45 text
খ͘͞࡞ͬͯૣΊʹϦϦʔεɺ ͕ͬͺΓେࣄ ࢥ͍͍ͭͨΞΠσΞ͙͢ʹ࣮ Ͱ͖ΔαΠζ͡Όͳ͍ͱɺͳΜ ͔ͩͬͨΕΔ
Slide 46
Slide 46 text
υΩϡϝϯςʔγϣϯ େ࡞ͳgemυΩϡϝϯτΛॻ͘ োน͕ߴ͍ ͦ͏͍͏ҙຯͰػೳগͳ͍ ΄͏͕ྑ͍
Slide 47
Slide 47 text
͍ͦͦํ͕͗͢͠Δπʔϧ ͬͯΒ͑ͳ͍ ίϯηϓτ͕ಛघͩͬͨΓ͢Δ ͱɺΘΒͣʹऴΘΔ
Slide 48
Slide 48 text
hocus_pocusͰͷࣦഊΛ׆͔ͯ͠ heavens_doorͰͬͯΈͨ͜ͱ
Slide 49
Slide 49 text
Ξχϝgif
Slide 50
Slide 50 text
Ξχϝgif͍͢͝
Slide 51
Slide 51 text
ʮݴ༿ʯͰͳ͘ʮ৺ʯͰ ཧղͰ͖Δʂ
Slide 52
Slide 52 text
Ͱɺ͜ͷϝιου͕ద༻Ͱ͖ΔRuby ͷϥΠϒϥϦͦΜͳʹଟ͘ͳ͍͔ʁ ࣮ࡍɺ͕ࣗ࡞ͬͨଞͷϥΠϒϥϦͰ͜ͷϝιου ͕׆༻Ͱ͖Δ͔Ͳ͏͔ߟ͑ͯΈ͚ͨͲɺ࣮ࡍͳ͔ͳ͔ νϟϯεͳͦ͞͏ ͯͳΘ͚ͰɺRubyͷϥΠϒϥϦΑΓJSͱ͔ͷ ϥΠϒϥϦͷํ͕⭐ΛूΊͦ͢͏ɺ͍ͬͯ͏ ͋ΔΜͩΑͳ͊
Slide 53
Slide 53 text
ͱ͜ΖͰɺ͜ͷϒϥβͰΞϓϦ Λ։ൃ͍ͯ͘͠ͱ͍͏ίϯηϓτ 2019ʹͳͬͯɺ͋ͷ”conductor”͕ Γ্͕ΓΛݟͤΔػӡ ͜Ε͔Β·ͩ·ͩՄೳੑͷ͋Δ ͳͷͰ
Slide 54
Slide 54 text
ͦ͜ͰɺϒϥβͰԿ͔͢ΔͭΛ ͏1ͭ
Slide 55
Slide 55 text
Case #3
Slide 56
Slide 56 text
ݱͷ ERਤ͕ݟ͍ͨʂ
Slide 57
Slide 57 text
ݱͰERਤݟ͍ͨͰ͢ΑͶʁ ͨͱ͑ͪΐͬͱΤϯλʔϓϥΠ ζͬΆ͍Ҋ݅ʹ్த͔Βࢀըͨ͠ ࣌ͱ͔
Slide 58
Slide 58 text
ͦ͜Ͱerd RailsΞϓϦʹmountͯ͠͏ engine ΞϓϦͷERਤΛϒϥβʹදࣔ ͍ͭͰʹૢ࡞
Slide 59
Slide 59 text
ૢ࡞ʁ create tableͱ͔alter tableͱ͔ migrationΛ࡞ɺ࣮ߦ migrationͷॻ͖ํΛ֮͑ΒΕͳ͍/ࢥ͍ग़ͤͳ͍ ਓʹ͓͢͢Ί migration ͕ʮݴ༿ʯͰͳ͘ʮ৺ʯͰ(ry
Slide 60
Slide 60 text
DEMO
Slide 61
Slide 61 text
Status of erd ͥΜͥΜະ UI͕͍Ζ͍ΖϏϛϣʔ ͬͱϒϥογϡΞοϓ͍ͨ͠ؾ࣋ͪ͋Δ͚ͲJSॻ͘ͷ ͠ΜͲ͍ coffeeͰࡶʹॻ͍ͯdecafͨ͠ίʔυ͕ϝϯςෆೳϨϕϧ ୭͔JS͕ಘҙͳํɺॿ͚͍ͯͩ͘͞ʂʂʂʂ(࣮)
Slide 62
Slide 62 text
erd https:/ /github.com/ amatsuda/erd
Slide 63
Slide 63 text
ͯ͞ɺมΘͬͯɺϒϥβ্ͰΤϯϓϥ ͬΆ͍ਤΛදࣔ͢ΔengineΛ͏1ͭ
Slide 64
Slide 64 text
Case #4
Slide 65
Slide 65 text
ݱͷ ࠓը໘ભҠਤ͕ݟ͍ͨʂ
Slide 66
Slide 66 text
͜Εݱͷ࣮ͳ routes.rb ΛݟΕϦιʔεͷ ҰཡΘ͔Δ Ͱͭͳ͕Γݟ͑ͳ͍
Slide 67
Slide 67 text
ͬͺը໘ભҠਤ
Slide 68
Slide 68 text
ίϯηϓτ ը໘ભҠਤͬͯੲΈΜͳखඳ͖ ͯͨ͠ͷ͚ͩͲɺߟ͑ͯΈͨΒ ͜ΕͬͯੜͰ͖ΔΜ͡Όͳ͍ ͔ʁ
Slide 69
Slide 69 text
roundabout
Slide 70
Slide 70 text
DEMO
Slide 71
Slide 71 text
ͬͯΔ͜ͱ E2EςετͰ࣮ߦ͞Εͨը໘ ભҠΛશͯه ͦͷ݁ՌΛਤࣔ
Slide 72
Slide 72 text
͜Ε͕ԿΛද͍ͯ͠Δͷ͔ ࣮ࡍʹ࣮͞Εͯͯςετ͞Εͯ ͍Δը໘ભҠΛه ͨͩͷ routes.rb ͷਤࣔͱҧ͏
Slide 73
Slide 73 text
ςετ͕ͪΌΜͱॻ͔Ε͍ͯΔ͔ͷ ֬ೝʹͳΔ ͋ΔҙຯΧόϨοδͷදࣔͷҰछ ͷΑ͏ͳͷͱݴ͑Δ͔
Slide 74
Slide 74 text
͜ͷgemͷΑ͞ ॻ͍ͨςετ͕ܗΛม͑ͨࢿ࢈ʹ ͳΔͷ͕Α͍
Slide 75
Slide 75 text
࣍͏1ͭɺςετࢿ࢈Λ׆͔ͭ͢ Λ͝հ
Slide 76
Slide 76 text
Case #5
Slide 77
Slide 77 text
ݱͷ RailsΞοϓάϨʔυͰσάϨ ͨ͘͠ͳ͍
Slide 78
Slide 78 text
still_life
Slide 79
Slide 79 text
still_lifeͰͰ͖Δ͜ͱ ςετΛΒͤͨࡍʹɺςετத ʹrender͞ΕͨHTMLΛશ෦ ϑΝΠϧʹॻ͖ग़͢
Slide 80
Slide 80 text
͍͢͝ྗٕͳϓϥάΠϯ
Slide 81
Slide 81 text
త ΞϓϦέʔγϣϯίʔυͷॻ͖͑ લޙʹɺϢʔβʔʹಧ͚͍ͯΔͷ ͕มԽ͍ͯ͠ͳ͍͜ͱΛ֬ೝͰ͖Δ
Slide 82
Slide 82 text
ಛ ը໘Λ౿ΜͰճΔ͚ͩͰྑͯ͘ɺ ΞαʔγϣϯΛॻ͔ͳͯ͘ྑ͍ ͷͰָνϯ
Slide 83
Slide 83 text
Ͳ͏͍͏࣌ʹ͏ͷ͔ ಛʹRailsͷΞοϓάϨʔυ͕ ఆ༻్ Ұൠతʹ֤छϦϑΝΫλϦϯάͷ ࢧԉʹͳΔͣ
Slide 84
Slide 84 text
ͦͦͷݩωλ 2011ʹɺΫοΫύουͷRails ͷόʔδϣϯΛ্͛Δ࣌ʹηίϯ ͞Μ͕ॻ͖ࣺͯͨεΫϦϓτ
Slide 85
Slide 85 text
https:/ /speakerdeck.com/a_matsuda/the-recipe- for-the-worlds-largest-rails-monolith?slide=129
Slide 86
Slide 86 text
cookpad
Slide 87
Slide 87 text
·͞ʹݱͷΛత֬ʹղܾ͢Δ ৬ਓٕ
Slide 88
Slide 88 text
gemԽʹ͋ͨͬͯɺҎԼͷશ໘αϙʔτ ΛՃ Capybara 3 RSpec 3 test-unit minitest
Slide 89
Slide 89 text
օ͞ΜͷݱͰ͏͖͡ Rails 5.2 -> 6.0 ͷΞοϓάϨʔυۀ͕࢝·Δͱࢥ͍·͕͢ɺ ͔ͳΓ༗༻͔͠Εͳ͍ͷͰɺ Ͳ͏ͧ͝׆༻͍ͩ͘͞
Slide 90
Slide 90 text
ͱ͜ΖͰɺ͜ͷϥΠϒϥϦͷओͳೳྗ ΞϓϦΛ͜͡։͚ͯಈ࡞Λه͢Δελϯυ ͜ͷೳྗͬͯɺ͜Εͦ͜ "heavens_door" ͡Ό͋Ͷ͔͑ʂ
Slide 91
Slide 91 text
ͱࢥ͚ͬͨͲɺͦͷ໊લͷgemطʹ औΒΕͯ͠·͍ͬͯͨͷͰ͋ͬͨ
Slide 92
Slide 92 text
໊લॏཁ gemͷ໊લ͚ͭΔͷ͍͠……
Slide 93
Slide 93 text
͜ΕΛ8ӽ͠ͰgemԽ͖͔͚ͨͬ͠ ࣗ࡞ςϯϓϨʔτΤϯδϯͷಈ࡞ݕূͷ ͨΊʹཉ͘͠ͳͬͨ ΠϯλʔωοτՈܭͷRailsΞοϓ άϨʔυͷࡍʹ͜ΕͷଘࡏΛࢥ͍ग़ͨ͠
Slide 94
Slide 94 text
Money Forward
Slide 95
Slide 95 text
ʮࣗ࡞ςϯϓϨʔτΤϯδϯʯ
Slide 96
Slide 96 text
Case #6
Slide 97
Slide 97 text
Himl
Slide 98
Slide 98 text
Himl ͖͔͚ͬɺӬγεςϜϚωδ ϝϯτͰຖ݄ͬͯΔOSSύον ձ
Slide 99
Slide 99 text
ͷ͋ͱͷҿΈձ
Slide 100
Slide 100 text
ӬγεςϜϚωδϝϯτ
Slide 101
Slide 101 text
kamipo͞Μͷ۪ஒ kamipo: ձࣾͰHamlͬͯΔ͚ͲɺHaml ͱ͔Slimͱ͔จ๏͕Ṗ֮͗ͯ͑͢ΒΕΜ ΘɻERBͰྑ͘ͳ͍ʁ me: ͍ʔɺHaml͍͍ͬ͢ΑɻERBʹ Δͱ͔ϜϦϜϦɻ
Slide 102
Slide 102 text
͔͠͠ɺ͋ΒͨΊͯɺHamlͷྑͬͯ͞ ͳΜͩΖ͏ʁ ͔֬ʹɺ͋ͷه߸ͨͪΛۦͨ͠จ๏ࣗମ Hamlͷྑ͞ͷຊ࣭Ͱͳ͍͔ Hamlͷྑ͞ɺλάΛػց͕ดͯ͘͡ΕΔ ͓͔͛ͰɺίϯύΠϧ͞ΕͨHTML͕valid ͳ͜ͱ͕อূ͞ΕΔͱ͜Ζ
Slide 103
Slide 103 text
͡Ό͋ɺHamlͷྑ͞ΛERBʹೖͯ͠ Εྑ͍ͷͰʁ
Slide 104
Slide 104 text
Αͦ͞͏ɺ͔͠Εͳ͍
Slide 105
Slide 105 text
ͷͰ࡞ͬͯΈͨ
Slide 106
Slide 106 text
Himl https:/ /github.com/ amatsuda/himl
Slide 107
Slide 107 text
ࠓճͷݱ… ਆాͷͱ͋Δډञ
Slide 108
Slide 108 text
Himlͷ։ൃΛ௨ͯ͡Θ͔ͬͨ͜ͱ
Slide 109
Slide 109 text
ډञͩͬͯݱͳΜʂ
Slide 110
Slide 110 text
·ͱΊ
Slide 111
Slide 111 text
ਓͳͥgemΛ࡞Δͷ͔ʁ Λղͨ͘Ί
Slide 112
Slide 112 text
ͨ͘͞Μݱʹస͕ͬͯΔ
Slide 113
Slide 113 text
͜͏͍͏ͷղ͖ํ͍͍Μ͡Ό ͳ͍Ͱ͠ΐ͏͔ʁ ͳ͔ͳָ͔͍͠Ͱ͢Α
Slide 114
Slide 114 text
Why Don't You Create Your Own Gems? gem࡞Ζʔͥʂ
Slide 115
Slide 115 text
end
Slide 116
Slide 116 text
me Name: Akira Matsuda Twitter: @a_matsuda GitHub: amatsuda