Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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
970
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
60
devsumi-2024-summer
onigra
4
1.7k
第一種低層住居専用地域
onigra
0
230
jaws-ug-ecspresso-meetup-20230808
onigra
0
1.7k
PHP-CS-FixerとかAtomとか
onigra
1
1.3k
プログラミング初心者でも始められるコミュニティへの参加と貢献
onigra
4
730
Techblog Deep Dive Meetup #1
onigra
0
1.8k
とある業務オペレーション自動化の話
onigra
0
950
about tsudura
onigra
0
250
Other Decks in Technology
See All in Technology
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
Terraform未経験の御様に対してどの ように導⼊を進めていったか
tkikuchi
2
430
Can We Measure Developer Productivity?
ewolff
1
150
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
220
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
120
The Rise of LLMOps
asei
5
1.2k
ドメイン名の終活について - JPAAWG 7th -
mikit
33
20k
ハイパーパラメータチューニングって何をしているの
toridori_dev
0
140
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
200
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Automating Front-end Workflow
addyosmani
1366
200k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
How STYLIGHT went responsive
nonsquared
95
5.2k
Documentation Writing (for coders)
carmenintech
65
4.4k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
A designer walks into a library…
pauljervisheath
203
24k
Practical Orchestrator
shlominoach
186
10k
KATA
mclloyd
29
14k
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ϚδͰ͍͢͝…
ฏຌͳ݁Ͱ͕͢ • ͲͪΒͷํ͕༏Ε͍ͯΔͱ͍͏Ͱͳ͘ɺ ϑϨʔϜϫʔΫΞʔΩςΫνϟͷࢥͱ ϢʔεέʔεΛཧղ͠ɺదͳٕज़બఆΛͯ͠ ͍͖·͠ΐ͏
ҟͳΔݴޠͷϑϨʔϜϫʔΫ ઃܭࢥʹ৮ΕΔ͜ͱɺ ઃܭͷ෯Λ͛Δ͜ͱʹͭͳ͕Δ