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
ISUCONで型をつける
euglena1215
1
65
3年でバックエンドエンジニアが5倍に増えても破綻しなかったアーキテクチャ そして、これから / Software architecture that scales even with a 5x increase in backend engineers in 3 years
euglena1215
11
4.4k
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
8
920
いつか使える ObjectSpace / Maybe useful ObjectSpace
euglena1215
2
180
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
580
Ruby の型に関する活動をやっている話 / Activities related to Ruby types
euglena1215
3
300
そろそろ理解する includes / Understanding includes
euglena1215
1
870
習うより慣れる Ruby AST / Ruby AST is better to get used to than to learn.
euglena1215
2
470
Railsでエンドポイントごとのテストカバレッジを測定する / Measuring Test Coverage per Endpoint in Rails
euglena1215
1
470
Other Decks in Technology
See All in Technology
Goで実践するBFP
hiroyaterui
1
120
#TRG24 / David Cuartielles / Post Open Source
tarugoconf
0
580
JAWS-UG20250116_iOSアプリエンジニアがAWSreInventに行ってきた(真面目編)
totokit4
0
140
生成AI × 旅行 LLMを活用した旅行プラン生成・チャットボット
kominet_ava
0
160
メールヘッダーを見てみよう
hinono
0
110
Amazon Route 53, 待ちに待った TLSAレコードのサポート開始
kenichinakamura
0
170
Docker Desktop で Docker を始めよう
zembutsu
PRO
0
170
embedパッケージを深掘りする / Deep Dive into embed Package in Go
task4233
1
220
新卒1年目、はじめてのアプリケーションサーバー【IBM WebSphere Liberty】
ktgrryt
0
130
Amazon Q Developerで.NET Frameworkプロジェクトをモダナイズしてみた
kenichirokimura
1
200
re:Invent2024 KeynoteのAmazon Q Developer考察
yusukeshimizu
1
150
ドメイン駆動設計の実践により事業の成長スピードと保守性を両立するショッピングクーポン
lycorptech_jp
PRO
13
2.2k
Featured
See All Featured
Being A Developer After 40
akosma
89
590k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
Mobile First: as difficult as doing things right
swwweet
222
9k
Building Applications with DynamoDB
mza
93
6.2k
A designer walks into a library…
pauljervisheath
205
24k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
Site-Speed That Sticks
csswizardry
3
270
How STYLIGHT went responsive
nonsquared
96
5.3k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.4k
4 Signs Your Business is Dying
shpigford
182
22k
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 ͬͯΔํ͍ͨΒ͍উखΛڭ͍͑ͯͩ͘͞ɻ