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
ぼくが考える最強のApplicationModel @表参道.rb #43
Search
YABOO JAPAN
February 07, 2019
0
660
ぼくが考える最強のApplicationModel @表参道.rb #43
YABOO JAPAN
February 07, 2019
Tweet
Share
More Decks by YABOO JAPAN
See All by YABOO JAPAN
RubyKaigiでもらった熱量がOSSに変換された話@AFTER RubyKaigi 2019
yaboojp
0
2.4k
RailsでViewModel導入に 挫折しかけてる話@表参道.rb #44
yaboojp
1
840
サービス開発する平成の君に 昭和の僕から伝えたい7つのこと@平成.rb #2
yaboojp
0
760
RailsのCacheつかってますか?@表参道.rb #44
yaboojp
0
720
夏休みの宿題 8/31にやらない話 @Otemachi.rb #14
yaboojp
0
320
大掃除 on Rails @Otemachi.rb #12
yaboojp
1
37
使わない機能の倒し方 @s-dev talks 〜サービス開発勉強会〜 大忘年LT大会
yaboojp
0
90
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5.1k
Documentation Writing (for coders)
carmenintech
67
4.5k
Designing for humans not robots
tammielis
250
25k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Mobile First: as difficult as doing things right
swwweet
222
9k
A Tale of Four Properties
chriscoyier
157
23k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Docker and Python
trallard
43
3.2k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Transcript
΅͕͘ߟ͑Δ࠷ڧͷ ApplicationModel @yaboojp on Omotesando.rb #43 2019/2/6
Self • Name: େ༅ Ӭ / @yaboojp • Jobs: •
22Inc. Co-Founder & CTO @தࠇ • ex NTTdata @ஙʙ๛ऱ • Location: ژ -> ౦ژ • Favorites: Ϗʔϧ, Իָ, όΠΫ, JALϚΠϧ
None
ActiveRecord͡Όͳ͍ ModelઃܭͲ͏ͯ͠·͔͢ʁ
ฐࣾ • جຊతʹɺActiveModelύλʔϯ • PORO(Plain Old Ruby Object)ͰStructΛར༻ ͢Δͷྑͦ͞͏ͱࢥ͍ͭͭ •
ActiveModel::Attributes͕Rails5.2͔Β͑Δ ͷͰͬͺΓActiveModel͕ྑͦ͞͏
ActiveModel::Attributes
ॳ LT͠Α͏ͱͯͨ͠ωλ • not Rails 5.2
ActiveModel::DirtyͰมߋݕ
ɹʊਓਓਓਓਓਓਓਓਓਓਓʊ ʼɹɹɹɹɹɹɹɹɹɹɹɹʻ ʼɹ ͢ωλ͕ͳ͘ͳͬͨ ɹʻ ʼɹɹɹɹɹɹɹɹɹɹɹɹʻ ɹʉY^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^ʉ
ॳ LT͠Α͏ͱͯͨ͠ωλ • Rails 5.2Ҏ߱ͰෆཁͳϋοΫ
݁
Thanks
Thanks
None
None
Ͳ͏ͯ͜͠͏ͳͬͨʁ
ແବ ແବ ແବ ແବ
ActiveModelͷؾ࣋ͪʹͳΔ
None
૯ͨΓͷମͨΓ
Model
Attributes
Dirty
Serializers::JSON • API࣮ͰΑ͘ΘΕͯΔ • ::XMLͱ͔ଞͷϑΥʔϚοτͳ͔ͬͨ • ActiveModel::SerializationΛؚΉ
Validations • ActiveModel::Modelʹؚ·ΕΔ
Validator • ActiveModel::Modelʹؚ·ΕΔ
Attribute_methods • ActiveModel::Attributesʹinclude͞ΕͯΔ • prefix/suffix͖ͷڞ௨ϝιουΛ֤attribute ʹఆٛͰ͖Δ • ෦࣮ɺmethod_missingࠇຐज़
Attribute_mutation_tracker • ActiveModel::DirtyͰΘΕ͍ͯΔΤϯςΟ ςΟΫϥε
Attribute_set • ActiveModel::AttributesͰΘΕ͍ͯΔΤϯ ςΟςΟΫϥε
Callbacks • ActiveModel::Validationsʹinclude͞ΕͯΔ • ͳͷͰɺinclude ActiveModel::ModelͰOK
Attribute_assignment • ActiveModel::Modelʹؚ·ΕΔ • assign_attributesϝιουΛఏڙ
Attribute • Attribute_setͰར༻͞Ε͍ͯΔΫϥε
Secure_password
Conversion • ActiveModel::Modelʹؚ·ΕΔ • ୯ମͰར༻͢Δ͜ͱͳͦ͞͏?
Naming • ActiveModel::Modelʹؚ·ΕΔ • ୯ମͰར༻͢Δ͜ͱͳͦ͞͏?
Serialization • ActiveModel::Serializers::JSONʹؚ·ΕΔ • serializable_hashϝιου͕ར༻ՄʹͳΔ • ୯ମͰΘͳ͍? ͏?
ActiveModel::Translation • ActiveModel::Modelʹؚ·ΕΔ • human_attribute_nameϝιουΛఏڙ
Forbidden_attributes_protection • ͝ΊΜͳ͍͞ ϝϞɿ ࢿྉ࡞͕ؒʹ߹Θͳ͔ͬͨͷͰɺௌऺʹ͍͔͚ͯΓΔɻ μϝͩͬͨΒ॓ͱͯ࣋ͬͯ͠ؼͬͯΒ͏ʢΈͳ͞Μʹʣ
ActiveModel::Lint • ͝ΊΜͳ͍͞
ActiveModel::Railtie • ͝ΊΜͳ͍͞
ActiveModel::Type • ͝ΊΜͳ͍͞
͜ΜͲͦ݁͜
None
We Are Hiring
ActiveModel::Thanks