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
XXXSerializer#to_json を地道に置き換えている話
Search
Shintani Teppei
September 07, 2023
Technology
0
150
XXXSerializer#to_json を地道に置き換えている話
Shintani Teppei
September 07, 2023
Tweet
Share
More Decks by Shintani Teppei
See All by Shintani Teppei
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
8
820
いつか使える ObjectSpace / Maybe useful ObjectSpace
euglena1215
2
160
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
450
Ruby の型に関する活動をやっている話 / Activities related to Ruby types
euglena1215
3
260
そろそろ理解する includes / Understanding includes
euglena1215
1
830
習うより慣れる Ruby AST / Ruby AST is better to get used to than to learn.
euglena1215
2
420
Railsでエンドポイントごとのテストカバレッジを測定する / Measuring Test Coverage per Endpoint in Rails
euglena1215
1
420
初めてrails/railsにバグレポートを出してみた
euglena1215
0
200
GitHub Copilot を使って自作ライブラリを作ってみよう/ Let's create your own library using GitHub Copilot!
euglena1215
0
310
Other Decks in Technology
See All in Technology
Taming you application's environments
salaboy
0
200
The Rise of LLMOps
asei
9
1.7k
安心してください、日本語使えますよ―Ubuntu日本語Remix提供休止に寄せて― 2024-11-17
nobutomurata
1
1k
アプリエンジニアのためのGraphQL入門.pdf
spycwolf
0
100
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.9k
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
AIチャットボット開発への生成AI活用
ryomrt
0
170
データプロダクトの定義からはじめる、データコントラクト駆動なデータ基盤
chanyou0311
2
340
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
200
Introduction to Works of ML Engineer in LY Corporation
lycorp_recruit_jp
0
140
飲食店データの分析事例とそれを支えるデータ基盤
kimujun
0
190
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.2k
Producing Creativity
orderedlist
PRO
341
39k
Making Projects Easy
brettharned
115
5.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Become a Pro
speakerdeck
PRO
25
5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
A better future with KSS
kneath
238
17k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Transcript
גࣜձࣾλΠϛʔɹShintani Teppei XXXSerializer#to_json Λ ಓʹஔ͖͍͑ͯΔ @euglena1215 ʲΦϑϥΠϯ։࠵ʳomotesando.rb #89
ࣗݾհ ৽୩ ฏʢ@euglena1215ʣ • גࣜձࣾλΠϛʔ • όοΫΤϯυΤϯδχΞ • omotesando.rb ࢀՃ2ճͰ͢
ΞϓϦέʔγϣϯίʔυͰ ͜Μͳ࣮ͯ͠·ͤΜ͔ʁ
None
͜ΕΛ
͜͏͍ͯ͠Δ
1 ͳ͍ͥͬͯΔͷ͔
ͳ͍ͥͬͯΔͷ͔ XXXSerializer#to_json Λͬͯ JSON ʹγϦΞϥΠζ͢Δͱ ࠔΔέʔε͕͋Δ → adapter option ΛөͰ͖ͳ͍
adapter option ͱʁ ADAPTER_OPTION_KEYS ʹఆٛ͞Ε͍ͯΔΦϓγϣϯɻ ݸਓతʹҰ൪Α͘͏ͷ key_transform Φϓγϣϯ ݸਓతʹศརͩͱࢥͬͯΔͷ fields
Φϓγϣϯ
adapter option ΛөͰ͖ͳ͍ͱʁ first_name, last_name Λ field ʹ࣋ͭ UserSerializer ͕ଘࡏ͢ΔͱԾఆɻ
key ͕ lower camel ͷ JSON Λग़ྗ͍ͨ͠ɻ firstName: “...”, lastName: “...” ʹ͍ͨ͠ʂ
UserSerializer.new ʹΩʔϫʔυҾͱͯ͠ key_transform Λ༩͑ͯ lower camel ʹͳΒͳ͍ɻ “lastName”ʹͳͬͯͳ͍... adapter
option ΛөͰ͖ͳ͍ͱʁ
XXXSerializer.new ͷҾʹͨ͠߹ adapter option ͱͯ͠Ͱͳ͘ɺ instance option ͱͯ͠ೝࣝ͞ΕΔɻͦͷͨΊɺXXXSerializer#to_json Λ͏ͱ ActiveModelSerializer
ͷػೳΛͬͯ key Λม͢Δ͜ͱͰ͖ͳ͍ɻ adapter option ΛөͰ͖ͳ͍ͱʁ
ActiveModelSerializer initializer ͰσϑΥϧτͷ key_transform ΛઃఆͰ͖Δ ͕ɺXXXSerializer#to_json Λͬͯ͠·͏ͱө͞Εͳ͍ͷࠔΔϙΠϯτͷ1 ͭɻ adapter
option ΛөͰ͖ͳ͍ͱʁ
Ͳ͏͢Ε͍͍ʁ adapter option ͱͯ͠ೝࣝͤ͞ɺkey Λ lower camel ʹม͢Δʹ ActiveModelSerializers::SerializableResource.new ͷҾͱͯ͢͠ඞཁ͕͋Δɻ
Controller Ͱ͘ॻ͚ΔΑ͏ʹͳ͍ͬͯΔɻͲͪΒͷॻ͖ํͰOKɻ Ͳ͏͢Ε͍͍ʁ
Ͳ͏͢Ε͍͍ʁ ͦͦ XXXSerializer#to_json Λͬͨ JSON γϦΞϥΠζͷํ๏ README ʹهࡌ͞Ε͓ͯΒͣɺREADME ʹʮγϦΞϥΠζʹ SerializableResource
Λ ͍·͠ΐ͏ʯͱॻ͔Ε͍ͯΔɻ
READMEʹॻ͍ͯ͋ΔͷͰ READMEΛಡ͏ ʙʙ
2 Ͳ͏͍ͬͯΔ͔
Ͳ͏͍ͬͯΔ͔ ಓʹॻ͖͍͔͑ͯ͘͠ͳ͍
Ͳ͏͍ͬͯΔ͔ Ͳ͏ͬͯյͣ͞ʹਐΊ͍͔ͯ͘ ֤ Serializer ʹରԠ͢ΔϚονϟͷதΛ༻ҙ͢Δ
Ͳ͏͍ͬͯΔ͔ request spec ͰϨεϙϯεʹରͯ͠JSONͷߏ͕Ұக͢Δ͔Ͳ͏͔Λ֬ೝ͠ɺ յΕ͍ͯͳ͍͜ͱΛશΤϯυϙΠϯτͰνΣοΫ͍ͯ͘͠ɻ APIఆٛ OpenAPI Ͱཧ͍ͯ͠ΔͷͰ committee-rails Λָ͕Ͱ͖ͦ͏ͳؾ͕
ͭͭ͠ࢼ͍ͤͯͳ͍ͷͰɺར༻ऀΛΛฉ͍ͯΈ͍ͨ 👀
·ͱΊ • XXXSerializer#to_json Ͱ JSON γϦΞϥΠζΛߦ͏ͱ adapter option ͕ө͞Εͳ͍ͷͰ README
ʹॻ͍ͯ͋Δํ๏ͰγϦΞ ϥΠζ͠Α͏ɻ • committee-rails ͬͯΔํ͍ͨΒ͍উखΛڭ͍͑ͯͩ͘͞ɻ