Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ginza-ruby-kaigi-01
Search
onigra
August 05, 2017
Technology
4
980
ginza-ruby-kaigi-01
https://ginzarb.github.io/kaigi01/
onigra
August 05, 2017
Tweet
Share
More Decks by onigra
See All by onigra
THE GOAL
onigra
3
64
devsumi-2024-summer
onigra
4
1.8k
第一種低層住居専用地域
onigra
0
230
jaws-ug-ecspresso-meetup-20230808
onigra
0
1.7k
PHP-CS-FixerとかAtomとか
onigra
1
1.3k
プログラミング初心者でも始められるコミュニティへの参加と貢献
onigra
4
740
Techblog Deep Dive Meetup #1
onigra
0
1.8k
とある業務オペレーション自動化の話
onigra
0
960
about tsudura
onigra
0
250
Other Decks in Technology
See All in Technology
データカタログを自作したけど 運用しなかった話@Findy Lunch LT「データカタログ 事例から学ぶメタデータ管理の実態」
ryo_suzuki
2
630
Advancing the 3D Geospatial Ecosystem in Japan via Global Collaborations
osgeojp
0
130
GDGoC開発体験談 - Gemini生成AI活用ハッカソン / GASとFirebaseで挑むパン屋のフードロス解決 -
hotekagi
1
610
高品質と高スピードを両立させるソフトウェアQA/Software QA that Supports Agility and Quality
goyoki
8
1.2k
Engineer Recruting Deck
siva_official
PRO
1
3.3k
12/2(月)のBedrockアプデ速報(re:Invent 2024 Daily re:Cap #1 with AWS Heroes)
minorun365
PRO
2
290
総会員数1,500万人のレストランWeb予約サービスにおけるRustの活用
kymmt90
3
2.8k
12/4(水)のBedrockアプデ速報(re:Invent 2024 Daily re:Cap #3 with AWS Heroes)
minorun365
PRO
2
340
農業用ダム監視を目的とした衛星SAR 干渉解析の適用性について
osgeojp
0
130
品質管理チームのEMとして大事にしていること / QA EM
nihonbuson
0
400
241130紅白ぺぱ合戦LT「編集の技術」
toya524287
5
590
システムリプレイスプロジェクト発足から7年、改めてコスト最適化に向き合う / replace and cost optimization
takumi
1
370
Featured
See All Featured
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Typedesign – Prime Four
hannesfritz
40
2.4k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Documentation Writing (for coders)
carmenintech
65
4.5k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
How To Stay Up To Date on Web Technology
chriscoyier
789
250k
Side Projects
sachag
452
42k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Transcript
Spring Frameworkͱൺֱֶͯ͠Ϳɺ WebΞϓϦέʔγϣϯϑϨʔϜϫʔΫͷ ׂ ͗Μ͟Rubyձٞ 01 2017-08-05 @onigra_
Yudai Suzuki / ླ༤େ @onigra_ onigra
͜ͷΛ͢Δʹ͋ͨͬͯ • ϓϩάϥϚʔͱͯ͠ࣄ͢Δ্Ͱɺ ॳΊͯͪΌΜͱֶΜͩͷ͕Ruby • ࣄͰ͏Web Application Frameworkɺ ΄ͱΜͲRailsͩͬͨ
Railsʹֶ͍ͭͯΜͰߦ͘͏ͪʹ • ใΛूΊͯΈΔͱɺRailsʹׂͱ ൷͕ଟ͍͜ͱʹؾͮ͘
ྫ • MVCͷఆٛʹ͍ͭͯ • ActiveRecord
ͳΔ΄Ͳ
ࠓͷ4݄ʹస৬
http://rubykaigi.org/2017/sponsors • http://rubykaigi.org/2017/sponsors
స৬ͯ͠ Java + Spring Frameworkʹ৮ΕΔ • ਖ਼֬ʹSpring Boot • Spring
BootɺSpring Frameworkͷ͍ͭ͘ ͔ͷϞδϡʔϧΛ౷߹ͯ͠ɺWebΞϓϦ έʔγϣϯΛߏஙͨ͘͢͠͠ͷ
Spring FrameworkΛ௨͠ ൷ͷ༰Λ վΊͯཧղ͢Δ
͜ͷൃදͷதͰ͍͑ͨ͜ͱ • ࢲͷΑ͏ʹɺϓϩάϥϛϯάWeb։ൃΛ RubyɺRails͔Β͡Ίͨํʑʹɺ ҟͳΔݴޠͷϑϨʔϜϫʔΫͷ ઃܭࢥύϥμΠϜʹ৮ΕΔ͜ͱʹΑΓɺ ৽͍͠ݟΛಘΔػձʹͳ͍͚ͬͯͨͩΕ ͍Ͱ͢
ҙ • ຊൃදͰপʹೖΓࠐΉͷΛආ͚ΔͨΊɺҎԼʹ͍ͭͯ ਂ͘౿ΈࠐΜͩ͠·ͤΜ • υϝΠϯۦಈઃܭ(DDD) • ΤϯλʔϓϥΠζΞϓϦέʔγϣϯΞʔΩςΫνϟύλʔ ϯ(PofEAA) •
͋͘·ͰRuby on RailsͱSpring Frameworkͷػೳͷൺֱͱ ͍͏؍Ͱ͓͠·͢
ࠂ
גࣜձࣾΤεΤϜΤεͰɺ ษڧձͷձఏڙΛ͡Ί·͢ • ࠷େͰ136໊·Ͱऩ༰ՄೳͳձΛఏڙͰ͖· ͢ • ৄࡉ@onigra_·Ͱ͓͍߹Θ͍ͤͩ͘͞ • ॴେ(ࣳެԂ) •
https://twitter.com/onigra_
Elastic Leadershipͷ ΠϕϯτΓ·͢ • ฐࣾͨͳ͢ͳ͓(@sunaot)͕ΤοηΠΛدߘ͠ ͨɺElastic LeadershipͷΠϕϯτΛߦ͍·͢ • ήετʹϨδϟϦʔϫʔΫε߹ಉձࣾͷ Shinichiro
OGAWA(@conceal_rs)͞ΜΛ͓ট͖͠ ·͢ • ͪ͜Βৄࡉ͕ܾ·Γ࣍ୈɺSNSʹͯࠂ͠·͢
σʔλΞΫηε
σʔλΞΫηε • Spring FrameworkʹɺRDBMSͷσʔλ ӬଓԽʹΞΫηε͢ΔͨΊͷϥΠϒϥϦͱ ͯ͠ɺSpring Data͕ଘࡏ͢Δ • Spring DataɺRDBMSҎ֎ͷσʔλιʔε
ʹରԠ࣮͕ͨ͠ଘࡏ͢Δ
Spring Data • https://projects.spring.io/spring-data/ • MongoDB • LDAP • ֎෦Web
API • Redis • Elasticsearch • etc…
Repository • Spring Core͕ఏڙ͍ͯ͠Δ • υϝΠϯΦϒδΣΫτͱσʔλΞΫηεͷ࣮Λ ্ͨ͠ͰɺRepositoryͦΕΒͷհΛߦ͏ • Spring Core͕ఏڙ͢ΔRepositoryʹର͠ɺ
Spring DataͷΛTemplateͱݺͿ
ϑϨʔϜϫʔΫͱͯ͠ͷ ActiveRecordͷσϝϦοτ • ϞσϧͱDB͕ີ݁߹ • Modelͱσʔλϕʔεઃܭ͕݁߹ͯ͠͠·͏ • ΦϒδΣΫτ͕σʔλϕʔεςʔϒϧͱରԠ͠ ͍ͯΔͱActiveRecordඇৗʹ༗ޮ •
σʔλϕʔεͷઃܭ͕ɺ͍͔ʹActiveRecordͰѻ͍ ͘͢͢ΔʹͲ͏͢Δ͔ɺͱ͍͏ํʹͳΓ͕ͪ
RepositoryͱTemplateΛ ༻͍࣮ͨ • Interfaceͷఆٛ • Interfaceʹର͠ɺσʔλιʔε͝ͱʹɺσʔ λΞΫηεͷ۩ମతͳ࣮Λߦ͏
RepositoryͱTemplateΛ ༻͍࣮ͨ
Կ͕خ͍͔͠ʁ • RepositoryͰఆٛͨ͠ΠϯλʔϑΣʔεͱɺ Templateͷ࣮Λ͚Δ͜ͱʹΑͬͯɺ ϏδωεϩδοΫͱ࣮ͷ͕Ͱ͖Δ • σʔλΞΫηεͷ࣮ΛΓସ͑Δ͚ͩͰɺΞϓ Ϧέʔγϣϯͷมߋ͕ྃ͢Δ • ϏδωεϩδοΫʹର࣮ͯ͠ͷมߋ͕༰қʹͳΔ
ActiveResource • ֎෦ͷWeb APIΛɺAcriveRecordΦϒδΣΫ τͷΑ͏ʹѻ͏͜ͱ͕Ͱ͖ΔΑ͏ʹͳΔgem • Rails2, 3ʹCoreʹ͕͋ͬͨɺ4Ͱ֎Εͨ
RubyͰRepository • rom-rb • http://rom-rb.org/ • Ruby Object Mapper •
HANAMIͷ෦Ͱ༻͞Ε͍ͯΔ • http://hanamirb.org/
Callbackͱ ΞεϖΫτࢦϓϩάϥϛϯά
ΞεϖΫτࢦϓϩάϥϛϯά ͱʁ • Aspect Oriented Programming • ΦϒδΣΫτͷ୯ҐͰ͏·͘Ͱ͖ͳ͍ɺ ΦϒδΣΫτؒΛ·͙ͨػೳΛʮہ໘ʯͱ͍͏ ୯Ґ͝ͱʹϞδϡʔϧԽ͢ΔϓϩάϥϛϯάύϥμΠ
Ϝ • ΦϒδΣΫτؒΛ·͙ͨػೳͷ͜ͱΛ ʮCrosscutting Concern(ԣஅతؔ৺ࣄ)ʯͱݺͿ
Crosscutting Concernͷྫ • Logging • Caching • Error Handling •
Transaction
ΞεϖΫτࢦϓϩάϥϛϯά Ͱ༻͍ΒΕΔ༻ޠ • Join Point • ΞϓϦέʔγϣϯ࣮ߦதͷɺ͋Δಛఆͷʮ࣌ʯΛࢦ͢ • Advice •
Join PointͰ࣮ߦ͞ΕΔॲཧ • Pointcut • Join Pointͷఆٛ
Spring AOP
Spring AOPͷ͍ํ • Join PointΛܾΊͯPointcutͱͯ͠ఆٛ͠ɺ PointcutͰߦ͏࣮ॲཧͰ͋ΔAdviceΛఆٛ͢ Δ • ಛఆͷΫϥεͷಛఆͷϝιου͕࣮ߦ͞ΕΔ લޙʹɺ࣮ߦ͢ΔॲཧΛఆٛ͢Δ
Pointcutͷఆٛ @Aspect public class RepositoryPointcut { // UserRepositoryͷsaveϝιου͕࣮ߦ͞ΕΔ࣌(Join Point)ΛPointcutͱͯ͠ఆٛ @Pointcut("execution(*
com.onigra.springaopsample.repository..UserRepository+.save(..))") public void save() {} }
Adviceͷఆٛ @Aspect @Component public class LoggingAdvice { private static final
Logger LOGGER = LoggerFactory.getLogger(LoggingAdvice.class); @Before(“com.onigra.springaopsample.aspect.UserPointcut.save()") public void beforeSave(JoinPoint joinPoint) { LOGGER.info("UserRepositoryͷsaveϝιου࣮ߦલʹϩάΛग़ྗ͢Δ"); } }
RailsͰݴ͏ͱCallback͔ͳ
AOPͱCallback ࣅͯඇͳΔͷ
RailsͷCallback • ActiveSupport::Callbacks#run_callbacksʹ ϒϩοΫΛ͢͜ͱͰ࣮ݱ • Rubyͷݴޠͱͯ͠ͷػೳΛར༻͍ͯ͠Δ
Spring AOP • όΠτίʔυม • ίϯύΠϧޙͷόΠφϦΛվม͠ɺॲཧΛࠩ ͠ࠐΉ
TransactionͰͷAOP • RailsɺActiveRecord::Transactions.transactionʹϒϩοΫΛ͢ • Spring FrameworkɺTransactionΛ͔͚͍ͨ ϝιουʹର͠ɺTransactionalΞϊςʔγϣϯ(Ճใ)Λ༩ • RailsͷΑ͏ʹɺϓϩάϥϜͷதͰ੍ޚΛߦ͏ํ๏ʹର͠ɺʮಛఆ ͷϝιουͷ࣮ߦ࣌ʹτϥϯβΫγϣϯΛ͔͚Δʯͱ͍͏
એݴΛߦ͏͜ͱΛɺʮએݴతτϥϯβΫγϣϯʯͱݺͿ • ※ϓϩάϥϛϯάʹΑΔτϥϯβΫγϣϯཧͰ͖Δ
MVCͱ ϨΠϠʔυΞʔΩςΫνϟ
ΞϓϦέʔγϣϯͷ ϨΠϠʔԽͷͱ MVC(MVC2, MVC Model2)ͷ શ͘ผͷʂʂʂ
Railsͷׂͷɺ ΞϓϦέʔγϣϯͷϨΠϠʔԽͷͱɺ MVCͷ͕ࠞͬͯ͟͠·͍ͬͯΔ ʢ͜ͱ͕ଟ͍ؾ͕͢Δʣ
͞Βʹͦ͜ʹDDDʹ͓͚ΔαʔϏεͱ PofEAAͷαʔϏεͷ͕ࠞͬͯ͟ େมͳ͜ͱʹ…
ΞϓϦέʔγϣϯઃܭʹ͓͚Δ ϨΠϠͷ֓೦ͱ • ݩClient-Server Modelͷߟ͑ํ • Webʹߟ͑ํ͕Ԡ༻͞Εɺൃల͖ͯͨ͠ • ͔͠͠ɺΞʔΩςΫνϟจݙʹΑ༷ͬͯʑ ͳϨΠϠʔͷ໊শ͕ଘࡏ͢ΔͷͰҙ͕ඞཁ
ΫϥΠΞϯταʔόϞσϧʹ͓ ͚Δ3ΞʔΩςΫνϟ • ϓϨθϯςʔγϣϯ: UI • ΞϓϦέʔγϣϯ: ϏδωεϩδοΫ • σʔλ:
σʔλΞΫηε
PofEAAʹ͓͚Δ3ΞʔΩςΫ νϟ • ϓϨθϯςʔγϣϯ: UI • υϝΠϯ: ϏδωεϩδοΫ • σʔλιʔε:
σʔλΞΫηε
͜ͷجຊͱͳΔ3Ͱ ߟ͑ͯݟΔ
Spring Framework • ϓϨθϯςʔγϣϯ • View(Template Engine(ThymeLeaf)) • Controller(Spring MVC)
• υϝΠϯ • Service(Spring Core) • Repository(Spring Core) • σʔλιʔε • Template(Spring Data) • ͦΕͧΕͷ͔ΒModelΛѻ͏
Spring Framework https://yo1000.gitbooks.io/self-study-spring/content/chapter1.html
Ruby on Rails • ϓϨθϯςʔγϣϯ • View(ActionView, View Template Engine(ERB))
• Controller(ActionController) • υϝΠϯ • Model(ActiveRecord, ActiveModel) • σʔλιʔε • Model(ActiveRecord)
༷ʑͳϨΠϠʔԽͷύλʔϯ͕ ଘࡏ͢Δ • ΞϓϦέʔγϣϯʹΑͬͯɺదͳϨΠϠԽ ҟͳΔ • จ຺ΞʔΩςΫνϟʹΑͬͯɺ໊শ͕ඃͬ ͨΓҟͳͬͨΓ૿͑ͨΓ͢Δͷʹҙ • ϨΠϠͷҙຯΛཧղ͠ɺదͳϨΠϠΛબ
͠Α͏
·ͱΊ
2ͭͷϑϨʔϜϫʔΫΛ ൺֱͯ͠ • RailsϢʔεέʔεΛߜͬͯɺׂΓͬͨઃܭʹ͍ͯ͠Δ • ͦͷɺϚον͠ͳ͍Ϗδωεཁ݅ʹΑͬͯɺਏΈવग़Δ • Spring Frameworkɺ͡Ί͔Β͍ϢʔεέʔεʹରԠ͢Δ ͜ͱΛࢦ͍ͯ͠Δ
• ෳࡶͳϏδωεཁ݅ɺظతͳ֦ுͷՄೳੑΛߟ͑Δͱɺ Spring Framework༏Εͨબࢶ • ҰํͰɺ͋Β͔͡Ίཧղ͓͖ͯ͘͠จ຺ɺ͕ࣝଟ͍
2ͭͷϑϨʔϜϫʔΫΛ ൺֱͯ͠ • ઃܭͷ෯Λ٘ਜ਼ʹͭͭ͠ɺ֮͑Δ͜ͱΛݮΒͯ͠։ ൃΛ্͛Δ͜ͱ͕Ͱ͖ΔActiveRecordΓศ ར • ໊শɺจ຺Λཧղ্ͨ͠ͰΞʔΩςΫνϟύλʔ ϯΛ͍͜ͳ͢ͷେม͔ͩΒɺେʹMVCͱ͍͏ ྨΛͨ͠ͷͰʁ
• ͦ͏ߟ͑ΔͱDHHϚδͰ͍͢͝…
ฏຌͳ݁Ͱ͕͢ • ͲͪΒͷํ͕༏Ε͍ͯΔͱ͍͏Ͱͳ͘ɺ ϑϨʔϜϫʔΫΞʔΩςΫνϟͷࢥͱ ϢʔεέʔεΛཧղ͠ɺదͳٕज़બఆΛͯ͠ ͍͖·͠ΐ͏
ҟͳΔݴޠͷϑϨʔϜϫʔΫ ઃܭࢥʹ৮ΕΔ͜ͱɺ ઃܭͷ෯Λ͛Δ͜ͱʹͭͳ͕Δ