Upgrade to Pro — share decks privately, control downloads, hide ads and more …

実践Railsアプリケーション設計 #meetup_rails / Practical Rails Application Design

Shu OGAWARA
October 30, 2019

実践Railsアプリケーション設計 #meetup_rails / Practical Rails Application Design

2019/10/30に「Meetup for Rails engineers -メドピア×リンカーズ×Classi開発事例-」(https://connpass.com/event/150554/ )で発表したスライドです。

Shu OGAWARA

October 30, 2019
Tweet

More Decks by Shu OGAWARA

Other Decks in Technology

Transcript

  1. 実践RailsΞϓϦέʔγϣϯ設計
    .FFUVQGPS3BJMTFOHJOFFST
    ϦϯΧʔζגࣜձࣾ େՏݪ म !FYQBKQ

    View Slide

  2. ͜ͷൃදͷϞνϕʔγϣϯ
    Ұൠతͳ3BJMTΞϓϦέʔγϣϯઃܭΛ
    ѻͬͨυΩϡϝϯτ͸গͳ͍

    View Slide

  3. Ұൠతιϑτ΢ΣΞ։ൃͷྲྀΕ
    ཁ݅ఆٛ
    ֎෦ઃܭ
    ಺෦ઃܭ
    ࣮૷
    ςετ
    ӡ༻

    View Slide

  4. Ұൠతιϑτ΢ΣΞ։ൃͷྲྀΕ
    ཁ݅ఆٛ
    ֎෦ઃܭ
    ಺෦ઃܭ
    ࣮૷
    ςετ
    ӡ༻
    ॻ੶ɺ8FCͱ΋ʹ
    ࢿྉ͕ॆ࣮
    8FC্ʹ
    ࢿྉ͕ॆ࣮

    View Slide

  5. Ұൠతιϑτ΢ΣΞ։ൃͷྲྀΕ
    ཁ݅ఆٛ
    ֎෦ઃܭ
    ಺෦ઃܭ
    ࣮૷
    ςετ
    ӡ༻
    ॻ੶ɺ8FCͱ΋ʹ
    ࢿྉ͕ॆ࣮
    8FC্ʹ
    ࢿྉ͕ॆ࣮
    ॻ੶͕ॆ࣮
    ந৅తͳ಺༰͕
    ଟ͍

    View Slide

  6. ઃܭϑΣʔζͷࢿྉ
    w ઃܭϑΣʔζͷϑϩʔΛ၆ᛌͯ͠
    ྲྀΕʹ͍ͭͯޠͬͨࢿྉ͸গͳ͍
    r ٯʹʮΦϒδΣΫτநग़ʯʮ໊෇͚ʯͳͲɺ
    ݸผͷϑΣʔζʹ͍ͭͯ࿩ͨ͠ࢿྉ͸ଟ͘
    ݟ͔ͭΔ

    View Slide

  7. ͜ͷൃදͷ໨త
    w ʮ3BJMTΛඪ४తʹ࢖ͬͯػೳ௥ՃΛ͢Δʯ
    ৔߹ͷઃܭͷྲྀΕΛ঺հ
    r طଘΞϓϦ΁ͷ৽ػೳ௥ՃΛͨ͠ۀ຿ܦݧΛ࿩͢
    w ʮී௨ͷ͜ͱΛաෆ଍ͳ͘΍Δʯ͜ͱͷ
    େ੾͞Λ఻͍͑ͨ
    r มΘͬͨςΫχοΫ͸ग़͖ͯ·ͤΜ

    View Slide

  8. ͜ͷൃදͷߏ੒
    w ֎෦ઃܭɺ಺෦ઃܭͷྲྀΕΛͦΕͧΕઆ໌
    r લϑΣʔζͷΞ΢τϓοτ͕
    ࣍ϑΣʔζͷΠϯϓοτʹͳΔΑ͏ʹߏ੒
    w ಺෦ઃܭ͸ৄ͘͠࿩͢
    r ईͷ౎߹Ͱɺ֎෦ઃܭ͸৮ΕΔఔ౓ʹ

    View Slide

  9. ࣮ࡍʹ௥Ճͨ͠৽ػೳ
    w ΞϓϦ಺ʹόϥόϥʹଘࡏ͍ͯ͠Δ
    ๏ਓͷ৘ใΛҰݩ؅ཧ͢Δػೳ

    View Slide

  10. ࣮ࡍʹ௥Ճͨ͠৽ػೳ
    ๏ਓͷ৘ใΛผʑʹ͍࣋ͬͯΔ

    View Slide

  11. ࣮ࡍʹ௥Ճͨ͠৽ػೳ
    w ΞϓϦέʔγϣϯ಺ʹόϥόϥʹଘࡏͯ͠
    ͍Δ๏ਓͷ৘ใΛҰݩ؅ཧ͢Δػೳ
    r ൃ஫৘ใ΍ड஫ީิ৘ใͱ๏ਓΛඥ෇͚Δ
    r डൃ஫σʔλ͕࡞੒͞Εͨ࣌఺Ͱɺ
    ඥ෇͚࡞ۀ͕ߦ͑ΔΑ͏ʹ͢Δ

    View Slide

  12. ֎෦ઃܭ
    ཁ݅ఆٛ
    ֎෦ઃܭ
    ಺෦ઃܭ
    ࣮૷
    ςετ
    ӡ༻

    View Slide

  13. ֎෦ઃܭͷྲྀΕ
    Ϣʔεέʔε
    நग़
    ը໘ઃܭ
    ը໘ભҠઃܭ
    Ϣʔεέʔε
    هड़࡞੒

    View Slide

  14. Ϣʔεέʔεهड़ͷྫ
    w ๏ਓؔ࿈σʔλΛ๏ਓʹඥ෇͚Δ
    r ৽ن๏ਓඥ෇͚ը໘Λ։͘
    r ֘౰ͷ๏ਓؔ࿈σʔλΛݟ͚ͭɺʮ๏ਓඥ෇͚ʯྻʹ͋Δʮ։͘ʯ
    ϦϯΫΛΫϦοΫ͢Δ
    r ๏ਓඥ෇͚ը໘ʹભҠ͢Δ
    r ඥ෇͚͍ͨ๏ਓΛɺ*%ɾ๏ਓ໊ɾॴࡏ஍͔Βݕࡧ͢Δ
    r ඥ෇͚͍ͨ๏ਓͷϥδΦϘλϯʹνΣοΫΛೖΕɺʮඥ෇͚ʯϘλ
    ϯΛΫϦοΫ͢Δ
    w ҟৗܥɿʮΩϟϯηϧʯΛԡ͢ͱϞʔμϧ΢Οϯυ΢͕ด͡Δ
    r ৽ن๏ਓඥ෇͚ը໘ʹ໭Γɺʮ๏ਓؔ࿈σʔλͷඥ෇͚͕ߦΘΕ·
    ͨ͠ʯͱදࣔ͞ΕΔ

    View Slide

  15. ಺෦ઃܭ
    ཁ݅ఆٛ
    ֎෦ઃܭ
    ಺෦ઃܭ
    ࣮૷
    ςετ
    ӡ༻

    View Slide

  16. ಺෦ઃܭͷྲྀΕ
    ΦϒδΣΫτ
    நग़
    &3ਤ
    ࡞੒
    ໊෇͚
    ໊લۭؒͱ
    ίϯτϩʔϥઃܭ

    View Slide

  17. ಺෦ઃܭͷྲྀΕ
    ΦϒδΣΫτ
    நग़
    &3ਤ
    ࡞੒
    ໊෇͚
    ໊લۭؒͱ
    ίϯτϩʔϥઃܭ
    ࿩͢ͷ͸͜ͷ෦෼

    View Slide

  18. ΦϒδΣΫτͷநग़
    w ໨తɿϢʔεέʔεͷதʹ͋Δ֓೦Λɺ
    ΦϒδΣΫτͱͯ͠நग़͢Δ
    w Ϣʔεέʔεهड़ͷதͷ໊ࢺͱಈࢺΛநग़
    r ໊ࢺ͸ΦϒδΣΫτͱϑΟʔϧυʹ෼ྨ
    r ಈࢺ͸ϝιουͱͯ͠ඥͮ͘ΦϒδΣΫτΛ
    ܾΊΔ
    r ը໘΍6*ཁૉͷ໊લɺ6*্ͷಈ࡞͸আ͘

    View Slide

  19. ໊ࢺͱಈࢺΛநग़
    w ๏ਓؔ࿈σʔλΛ๏ਓʹඥ෇͚Δ
    r ৽ن๏ਓඥ෇͚ը໘Λ։͘
    r ֘౰ͷ๏ਓؔ࿈σʔλΛݟ͚ͭɺʮ๏ਓඥ෇͚ʯྻʹ͋Δʮ։͘ʯ
    ϦϯΫΛΫϦοΫ͢Δ
    r ๏ਓඥ෇͚ը໘ʹભҠ͢Δ
    r ඥ෇͚͍ͨ๏ਓΛɺ*%ɾ๏ਓ໊ɾॴࡏ஍͔Βݕࡧ͢Δ
    r ඥ෇͚͍ͨ๏ਓͷϥδΦϘλϯʹνΣοΫΛೖΕɺʮඥ෇͚ʯϘλ
    ϯΛΫϦοΫ͢Δ
    w ҟৗܥɿʮΩϟϯηϧʯΛԡ͢ͱϞʔμϧ΢Οϯυ΢͕ด͡Δ
    r ৽ن๏ਓඥ෇͚ը໘ʹ໭Γɺʮ๏ਓؔ࿈σʔλͷඥ෇͚͕ߦΘΕ·
    ͨ͠ʯͱදࣔ͞ΕΔ

    View Slide

  20. ໊ࢺͱಈࢺΛநग़
    w ๏ਓؔ࿈σʔλΛ๏ਓʹඥ෇͚Δ
    r ৽ن๏ਓඥ෇͚ը໘Λ։͘
    r ֘౰ͷ๏ਓؔ࿈σʔλΛݟ͚ͭɺʮ๏ਓඥ෇͚ʯྻʹ͋Δʮ։͘ʯ
    ϦϯΫΛΫϦοΫ͢Δ
    r ๏ਓඥ෇͚ը໘ʹભҠ͢Δ
    r ඥ෇͚͍ͨ๏ਓΛɺ*%ɾ๏ਓ໊ɾॴࡏ஍͔Βݕࡧ͢Δ
    r ඥ෇͚͍ͨ๏ਓͷϥδΦϘλϯʹνΣοΫΛೖΕɺʮඥ෇͚ʯϘλ
    ϯΛΫϦοΫ͢Δ
    w ҟৗܥɿʮΩϟϯηϧʯΛԡ͢ͱϞʔμϧ΢Οϯυ΢͕ด͡Δ
    r ৽ن๏ਓඥ෇͚ը໘ʹ໭Γɺʮ๏ਓؔ࿈σʔλͷඥ෇͚͕ߦΘΕ·
    ͨ͠ʯͱදࣔ͞ΕΔ

    View Slide

  21. ໊ࢺ
    ๏ਓ
    ๏ਓؔ࿈
    σʔλ
    *%
    ๏ਓ໊
    ॴࡏ஍

    View Slide

  22. ໊ࢺͷؔ܎ͷ੔ཧ
    ๏ਓ
    ๏ਓؔ࿈
    σʔλ
    *%
    ๏ਓ໊
    ॴࡏ஍
    ๏ਓ͕࣋ͭ

    View Slide

  23. ໊ࢺͷؔ܎ͷ੔ཧ
    ๏ਓ
    ๏ਓؔ࿈
    σʔλ
    *%
    ๏ਓ໊
    ॴࡏ஍
    डൃ஫
    σʔλ
    ๏ਓͱ
    डൃ஫σʔλΛ
    ݁ͼ͚ͭΔ

    View Slide

  24. ໊ࢺͷ෼ྨ
    ๏ਓ
    ๏ਓؔ࿈
    σʔλ
    *%
    ๏ਓ໊
    ॴࡏ஍
    ΦϒδΣΫτ ϑΟʔϧυ

    View Slide

  25. ಈࢺͷ݁ͼ͚ͭ
    ๏ਓ
    ๏ਓؔ࿈
    σʔλ
    ݕࡧ͢Δ
    ඥ෇͚Δ

    View Slide

  26. ಈࢺͷ݁ͼ͚ͭ
    ๏ਓ
    ๏ਓؔ࿈
    σʔλ
    ݕࡧ͢Δ
    ඥ෇͚Δ
    ๏ਓΛݕࡧ͢Δ

    View Slide

  27. ಈࢺͷ݁ͼ͚ͭ
    ๏ਓ
    ๏ਓؔ࿈
    σʔλ
    ݕࡧ͢Δ
    ඥ෇͚Δ
    ๏ਓؔ࿈σʔλ
    ๏ਓͱ݁ͼ͚ͭΔʁ

    View Slide

  28. ಈࢺͷ݁ͼ͚ͭ
    ๏ਓ
    ๏ਓؔ࿈
    σʔλ
    ݕࡧ͢Δ
    ඥ෇͚Δ
    ๏ਓͱडൃ஫σʔλΛ
    ؔ࿈σʔλΛհͯ͠
    ݁ͼ͚ͭΔ
    डൃ஫
    σʔλ

    View Slide

  29. &3ਤͷ࡞੒

    View Slide

  30. &3ਤͷ࡞੒
    w ΦϒδΣΫτͲ͏͠ͷؔ܎Λ੔ཧ͢Δ
    r ରɺରଟɺଟରଟ
    r ਌ࢠؔ܎
    w Ϟσϧ࣮૷ʹͦͷ··࢖͑ΔਤΛ໨ࢦ͢

    View Slide

  31. &3ਤ
    w %SBXJP͕΂ΜΓ

    View Slide

  32. &3ਤ
    w Ϋϥεਤͷ୅ΘΓʹಈ࡞Λॻ͍ͯ΋ྑ͍

    View Slide

  33. ໊෇͚

    View Slide

  34. ࢠᐌ͘ɺ໊લॏཁ
    ໊લॏཁ
    ը૾Ҿ༻ݩɿ :VLJIJSP.BUTVNPUPʢ[email protected][ʣ͞Μ 5XJUUFS
    [email protected][

    View Slide

  35. ͳͥ΍Δ͔ʁ
    w ͜ͷஈ֊Ͱ໊લΛܾΊΔ͜ͱͰɺ
    ͳΜͱͳܾ͘·໊ͬͨલͰօ͕ݺͿ
    ࣄଶΛ๷͙͜ͱ͕Ͱ͖Δ
    r ࠷௿ݶɺը໘ͱΦϒδΣΫτʹ໊લΛ෇͚Δ

    View Slide

  36. ͳͥ͜ͷλΠϛϯάͰ΍Δ͔ʁ
    w ΦϒδΣΫτɾϑΟʔϧυɾϝιου͕
    நग़͞Ε্ͨͰ੔ཧ͞Εɺ
    ؔ܎͕໌Β͔ʹͳ͔ͬͨΒ
    ʹ֓೦͕੾Γ෼͚ΒΕ͔ͨΒ

    View Slide

  37. ֓೦Λ੾Γ෼͚Δʹ໾ׂΛཧղ͢Δ
    ద੾ͳ໊લΛ͚ͭΒΕΔͱݴ͏͜ͱ͸ɺ
    ͦͷػೳ͕ਖ਼͘͠ཧղ͞Εͯɺઃܭ͞Ε͍ͯΔͱ͍͏͜ͱͰɺ
    ٯʹ;͞Θ໊͍͠લ͕͚ͭΒΕͳ͍ͱ͍͏͜ͱ͸ɺ
    ͦͷػೳ͕Ռͨ͢΂͖໾ׂΛઃܭऀࣗ਎΋े෼ཧղͰ͖͍ͯͳ͍
    ͱ͍͏͜ͱͳͷͰ͸ͳ͍Ͱ͠ΐ͏͔
    Ҿ༻ݩɿϓϩάϥϚ͕஌Δ΂͖ͷ͜ͱ r ໊લॏཁʢ.BU[ʣ
    IUUQTϓϩάϥϚ͕஌Δ΂͖ͷ͜ͱDPNΤοηΠ໊લॏཁ


    View Slide

  38. ໊෇͚ͷ΍Γํ
    w ·ͣ͸։ൃऀͲ͏͠Ͱର৅ͷೝࣝ߹Θͤ
    r ԿΛ͢Δը໘͔ɺԿΛද͢ΦϒδΣΫτ͔
    w શһ͕ೲಘ͢Δ౴͕͑ग़Δ·Ͱɺ
    ϒϨετΛ܁Γฦ͢
    r ग़ͨ୯ޠ͕ͬ͘͠Γདྷͳ͍৔߹͸
    γιʔϥεʢྨޠࣙయʣΛௐ΂Δ

    View Slide

  39. ໊෇͚ͷ஫ҙ఺
    w ӳޠͱ೔ຊޠͷ྆ํͰ໊લΛ෇͚͓ͯ͘
    r ӳޠ͸ίʔυ಺ͷࠞཚ๷ࢭ
    r ೔ຊޠ͸ίϛϡχέʔγϣϯͷࠞཚ๷ࢭ
    w طଘίʔυʹଘࡏ͢Δ໊લͱॏෳ͠ͳ͍Α͏
    ʹ͢Δ

    View Slide

  40. ໊෇͚͕ऴΘͬͨΒ
    w ཁ݅ఆٛ࣌ʹͳΜͱͳ͘࢖ΘΕ໊͍ͯͨલΛ
    શഇ͢Δ
    r Ϗδωεଆʹ఻͑ͯ৽໊͍͠લΛపఈ͢Δͱ
    ໿ଋ͢Δ
    r ݹ໊͍લ͕࢖ΘΕ͍ͯͨΒ͍͍ͪͪగਖ਼͢Δ
    r Ϣʔεέʔεهड़ɺ&3ਤʹ൓ө͢Δ

    View Slide

  41. ࣮ࡍʹ໊͍ͭͨલ
    "DUJWJUZ๏ਓؔ࿈σʔλ
    $PSQPSBUJPO๏ਓ
    6OBTTPDJBUFE"DUJWJUZ
    ඥ෇͚଴ͪ๏ਓؔ࿈σʔλ
    3FBTTPDJBUFE3FRVFTU
    ๏ਓؔ࿈σʔλඥ෇͚मਖ਼ґཔ

    View Slide

  42. ಺෦ઃܭͷྲྀΕ
    ΦϒδΣΫτ
    நग़
    &3ਤ
    ࡞੒
    ໊෇͚
    ໊લۭؒͱ
    ίϯτϩʔϥઃܭ
    㾎 㾎 㾎
    ࠓճ͸ׂѪ

    View Slide

  43. 4DBGGPMEͰͻͳܗ࡞ͬͯ
    ։ൃ։࢝

    View Slide

  44. ͜ͷྲྀΕͰઃܭͨ݁͠Ռ
    w ։ൃத΋ӡ༻։࢝ޙ΋ɺϞσϧͷ࣮૷͕
    ΩϨΠͳ··อͨΕ͍ͯΔ
    w Ϗδωεଆͱʮ໊લॏཁʯΛѲͬͨঢ়ଶͰ
    ։ൃΛਐΊΒΕͨ
    r ్தɺ໊લͷมߋ͕͋ͬͯ΋৽໊͍͠લΛ
    పఈͰ͖ͨ

    View Slide

  45. ·ͱΊ
    w Ϣʔεέʔεهड़͔ΒΦϒδΣΫτΛநग़
    ͯ͠ɺ&3ਤʹ੔ཧ͢Δ
    w ໊લॏཁɺඞ໊ͣ෇͚ΛڬΉ
    w ී௨ͷ͜ͱΛաෆ଍ͳ͘΍Δ

    View Slide