Slide 1

Slide 1 text

େن໛ Padrino ΞϓϦέʔγϣϯ Rails Ҡߦ 2016/04/27 @ttanimichi (C) Tsukuru Tanimichi, 2016 1

Slide 2

Slide 2 text

ࣗݾ঺հ • @ttanimichi • 2014೥6݄ʙ גࣜձࣾ Aiming • ڞ௨ج൫ͷ։ൃΛ͍ͯͨ͠ • ࠷ۙήʔϜλΠτϧʹҟಈ • https://github.com/ttanimichi • [email protected] (C) Tsukuru Tanimichi, 2016 2

Slide 3

Slide 3 text

ݬౝઓهάϦϑΥϯ (C) Tsukuru Tanimichi, 2016 3

Slide 4

Slide 4 text

؀ڥ • Ruby 2.0 • Padrino 0.11 • MySQL 5.5 • nginx • Redis (C) Tsukuru Tanimichi, 2016 4

Slide 5

Slide 5 text

rake stats % bin/rake stats +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | +----------------------+-------+-------+---------+---------+-----+-------+ | Controllers | 2984 | 2566 | 50 | 302 | 6 | 6 | | Helpers | 86 | 86 | 0 | 1 | 0 | 84 | | Models | 15810 | 13029 | 422 | 1513 | 3 | 6 | | Mailers | 0 | 0 | 0 | 0 | 0 | 0 | | Javascripts | 11577 | 7916 | 1 | 809 | 809 | 7 | | Libraries | 19329 | 13621 | 693 | 1754 | 2 | 5 | | Controller specs | 223 | 181 | 0 | 2 | 0 | 88 | | Lib specs | 4404 | 3603 | 6 | 6 | 1 | 598 | | Model specs | 31852 | 26255 | 0 | 19 | 0 | 1379 | | Request specs | 15 | 13 | 0 | 0 | 0 | 0 | | Service specs | 24027 | 19808 | 3 | 37 | 12 | 533 | +----------------------+-------+-------+---------+---------+-----+-------+ | Total | 110307 | 87078 | 1175 | 4443 | 3 | 17 | +----------------------+-------+-------+---------+---------+-----+-------+ Code LOC: 37218 Test LOC: 49860 Code to Test Ratio: 1:1.3 (C) Tsukuru Tanimichi, 2016 5

Slide 6

Slide 6 text

rake stats % bin/rake stats +----------------------+-------+-------+---------+---------+-----+-------+ | Name | Lines | LOC | Classes | Methods | M/C | LOC/M | ... | Models | 15810 | 13029 | 422 | 1513 | 3 | 6 | ... +----------------------+-------+-------+---------+---------+-----+-------+ 400 Models (C) Tsukuru Tanimichi, 2016 6

Slide 7

Slide 7 text

(C) Tsukuru Tanimichi, 2016 7

Slide 8

Slide 8 text

rake stats • COOKPAD Ͱ 1500 Models • lib/ ҎԼʹ΋ Model ͬΆ͍Ϋϥε͕100ݸ͘ Β͍͋ͬͨ • ͋ΘͤΔͱ 500 Models ͘Β͍ • COOKPAD ͷ 1/3 ͘Β͍ʁʁ (C) Tsukuru Tanimichi, 2016 8

Slide 9

Slide 9 text

ੈք࠷େͷ Padrino ΞϓϦέʔγϣϯʁʁ (C) Tsukuru Tanimichi, 2016 9

Slide 10

Slide 10 text

ͭΒΈ • rake spec ʹ1͔͔࣌ؒΔ • autoload ࢖ͬͯͳ͔ͬͨ • ىಈʹ2෼͘Β͍͔͔Δ • spec Ұ࣮݅ߦ͢Δ͚ͩͰ΋2෼ • AR ͷΩϟογϡ͕ޮ͍ͯͳ͍ͬΆ͍ʁʁ (C) Tsukuru Tanimichi, 2016 10

Slide 11

Slide 11 text

ґଘϥΠϒϥϦ • activerecord 3.2 • activesupport 3.2 ͭ·Γɺ΄ͱΜͲ Rails3 (C) Tsukuru Tanimichi, 2016 11

Slide 12

Slide 12 text

͜Ε Rails ʹҠߦͰ͖ΔΜ͡ΌͶʁ (C) Tsukuru Tanimichi, 2016 12

Slide 13

Slide 13 text

͍ͭΧοͱͳͬͯ... (C) Tsukuru Tanimichi, 2016 13

Slide 14

Slide 14 text

(C) Tsukuru Tanimichi, 2016 14

Slide 15

Slide 15 text

Ҡߦίετ • Padrino ͔Β Rails ΁ͷҠߦ • activerecord ͷόʔδϣϯΛ্͛Δ • activesupport ͷόʔδϣϯΛ্͛Δ • ͍ͭͰʹ Ruby ͷόʔδϣϯ΋্͛Δ (C) Tsukuru Tanimichi, 2016 15

Slide 16

Slide 16 text

ํ਑ • ·ͣ͸ Rails4 Ͱಈ͔͢͜ͱ͚ͩߟ͑Δ • ʮ͍ͭͰʹϦϑΝΫλϦϯάʯ͸ೝΊͳ͍ • ػցతʹҠߦ࡞ۀ͚ͩ͢Δ • ϦϑΝΫλϦϯά΍ࡉ͔͍վળ͸Ҡߦޙʹ͍͘ ΒͰ΋Ͱ͖Δ (C) Tsukuru Tanimichi, 2016 16

Slide 17

Slide 17 text

ํ਑ • Rails΁ͷҠߦͱ͍͏ʮେ͖͍໰୊ʯ • ಉ࣌ʹϦϑΝΫλϦϯά΋͠͸͡ΊΔͱӬ ԕʹҠߦ࡞ۀ͕׬ྃ͠ͳ͍ • Ϗδωεଆ͕ΩϨΔ → Ҡߦ͕ࣦഊ • ͱʹ͔͘ػցతʹҠߦ͢Δ • Կ΋ߟ͑ͣʹ spec ͕ίέ͍ͯΔॴΛ௚͢ (C) Tsukuru Tanimichi, 2016 17

Slide 18

Slide 18 text

Ҡߦखॱ • ͱʹ͔͘·ͣ͸σΟϨΫτϦߏ଄Λ࡞Δ • Padrino ଆ͔Β Models ͳͲΛҠ͍ͯ͘͠ • bundle exec rspec ͕ಈ͘ͱ͜Ζ·Ͱ͸Ұਓ Ͱ΋ͬͯ͘ • rails new • rails generate rspec:install • database.yml ͷઃఆͱ͔ (C) Tsukuru Tanimichi, 2016 18

Slide 19

Slide 19 text

(C) Tsukuru Tanimichi, 2016 19

Slide 20

Slide 20 text

(C) Tsukuru Tanimichi, 2016 20

Slide 21

Slide 21 text

bundle exec rspec ಈ͍ͨ • ͔͜͜Βઌ͸ϝϯόʔʹ࡞ۀΛৼΔ • ͱʹ͔͘ spec ͑͞ಈ͚͹෼ۀͰ͖Δ • ෼୲ͯ͠ spec ͕ίέ͍ͯΔ෦෼Λमਖ਼ (C) Tsukuru Tanimichi, 2016 21

Slide 22

Slide 22 text

੝େʹίέΔ spec (C) Tsukuru Tanimichi, 2016 22

Slide 23

Slide 23 text

(C) Tsukuru Tanimichi, 2016 23

Slide 24

Slide 24 text

੝େʹίέΔ spec • ͲΜ͚ͩίέͯͯ΋ spec ͕ಈ͖͑͢͞Ε͹म ਖ਼͸ϝϯόʔʹ෼୲Ͱ͖Δ • Active Record 3 ͱ 4 ͷඇޓ׵ͱ͔ • ઃఆ·ΘΓͷ໰୊ • padrino helper ΁ͷґଘ • ಉ໊͡લͷϝιουΛఆٛͯ͠ rails ͷ helper ΁ΞΫηε͢ΔΑ͏मਖ਼ (C) Tsukuru Tanimichi, 2016 24

Slide 25

Slide 25 text

Ͱ͖·ͨ͠ % rails -v Rails 4.2.4 % ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin14] ຊ൪؀ڥͰطʹಈ͍ͯ·͢ (C) Tsukuru Tanimichi, 2016 25

Slide 26

Slide 26 text

ৼΓฦΓ (C) Tsukuru Tanimichi, 2016 26

Slide 27

Slide 27 text

(C) Tsukuru Tanimichi, 2016 27

Slide 28

Slide 28 text

ৼΓฦΓ • Ҡߦίετʹݟ߹͏͚ͩͷϝϦοτ͕͋ͬͨͷ ͔ͳ͔ͬͨͷ͔͸ʮ෼͔Βͳ͍ʯ • ϝϯόʔͷ։ൃʹର͢ΔϞνϕʔγϣϯΞοϓ • େֻ͔ΓͳҠߦʹ͸༐ؾͱܾஅྗ͕ඞཁ • Padrino ͷ··࠷௿ݶͷվળ͚ͩ͢Δͬͯબ୒ ࢶ΋ΞϦ͔ͩͬͨ΋ (C) Tsukuru Tanimichi, 2016 28

Slide 29

Slide 29 text

͓·͚ (C) Tsukuru Tanimichi, 2016 29

Slide 30

Slide 30 text

؅ཧը໘ • ຊମͱ؅ཧը໘͸ผΞϓϦέʔγϣϯ • ؅ཧπʔϧଆ͸ຊମଆͷ Model Λࢀর • ؅ཧπʔϧଆ͸Ұ୴ Padrino ͷ··࢒ͨ͠ • Ұ෦ͷ Model ͕ Rails.env ʹґଘʢྑ͘ͳ͍ʣ • Padrino ͷ৔߹͸ Padrino.env Λࢀর͍ͨ͠ (C) Tsukuru Tanimichi, 2016 30

Slide 31

Slide 31 text

Rails = Padrino ΩλίϨ Rails = Padrino Rails.env #=> "development" ॳظԽ࣌ʹ Rails ͱ͍͏ఆ਺Λఆٛ ※ ωλͰ͢ ※ ؅ཧը໘΋ Rails ΁ͷҠߦ࡞ۀΛࠓ͍ͯ͠ΔΑ ※ ؅ཧը໘ͷ Rails Ҡߦ΋΄ͱΜͲ׬ྃ (C) Tsukuru Tanimichi, 2016 31

Slide 32

Slide 32 text

͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ (C) Tsukuru Tanimichi, 2016 32