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
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
250
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
630
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
150
Adopting Jetpack Compose in Your Existing Project - GDG DevFest Bangkok 2024
akexorcist
0
110
複雑なState管理からの脱却
sansantech
PRO
1
150
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
140
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
200
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
320
OCI Vault 概要
oracle4engineer
PRO
0
9.7k
Engineer Career Talk
lycorp_recruit_jp
0
190
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
690
Featured
See All Featured
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
Documentation Writing (for coders)
carmenintech
65
4.4k
Art, The Web, and Tiny UX
lynnandtonic
297
20k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
We Have a Design System, Now What?
morganepeng
50
7.2k
How GitHub (no longer) Works
holman
310
140k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Six Lessons from altMBA
skipperchong
27
3.5k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Product Roadmaps are Hard
iamctodd
PRO
49
11k
What's new in Ruby 2.0
geeforr
343
31k
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 ͬͯΔํ͍ͨΒ͍উखΛڭ͍͑ͯͩ͘͞ɻ