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
170
XXXSerializer#to_json を地道に置き換えている話
Shintani Teppei
September 07, 2023
Tweet
Share
More Decks by Shintani Teppei
See All by Shintani Teppei
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
210
ISUCONで型をつける
euglena1215
1
120
3年でバックエンドエンジニアが5倍に増えても破綻しなかったアーキテクチャ そして、これから / Software architecture that scales even with a 5x increase in backend engineers in 3 years
euglena1215
11
5.3k
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
8
1.1k
いつか使える ObjectSpace / Maybe useful ObjectSpace
euglena1215
2
230
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
830
Ruby の型に関する活動をやっている話 / Activities related to Ruby types
euglena1215
3
390
そろそろ理解する includes / Understanding includes
euglena1215
1
940
習うより慣れる Ruby AST / Ruby AST is better to get used to than to learn.
euglena1215
2
650
Other Decks in Technology
See All in Technology
ドキュメントはAIの味方!スタートアップのアジャイルを加速するADR
kawauso
3
340
Figma + Storybook + PlaywrightのMCPを使ったフロントエンド開発
yug1224
3
170
事業価値と Engineering
recruitengineers
PRO
1
190
広島銀行におけるAWS活用の取り組みについて
masakimori
0
130
Android Studio の 新しいAI機能を試してみよう / Try out the new AI features in Android Studio
yanzm
0
270
浸透しなさいRFC 5322&7208
hinono
0
120
[CVPR2025論文読み会] Linguistics-aware Masked Image Modelingfor Self-supervised Scene Text Recognition
s_aiueo32
0
210
知られざるprops命名の慣習 アクション編
uhyo
10
2.4k
[CV勉強会@関東 CVPR2025 読み会] MegaSaM: Accurate, Fast, and Robust Structure and Motion from Casual Dynamic Videos (Li+, CVPR2025)
abemii
0
190
Goでマークダウンの独自記法を実装する
lag129
0
210
あなたの知らない OneDrive
murachiakira
0
230
JOAI発表資料 @ 関東kaggler会
joai_committee
1
260
Featured
See All Featured
Become a Pro
speakerdeck
PRO
29
5.5k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
Code Reviewing Like a Champion
maltzj
525
40k
Gamification - CAS2011
davidbonilla
81
5.4k
A better future with KSS
kneath
239
17k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
Practical Orchestrator
shlominoach
190
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 ͬͯΔํ͍ͨΒ͍উखΛڭ͍͑ͯͩ͘͞ɻ