$30 off During Our Annual Pro Sale. View Details »
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
850
いつか使える ObjectSpace / Maybe useful ObjectSpace
euglena1215
2
160
rbs-inlineを導入してYARDからRBSに移行する
euglena1215
1
490
Ruby の型に関する活動をやっている話 / Activities related to Ruby types
euglena1215
3
270
そろそろ理解する includes / Understanding includes
euglena1215
1
850
習うより慣れる Ruby AST / Ruby AST is better to get used to than to learn.
euglena1215
2
430
Railsでエンドポイントごとのテストカバレッジを測定する / Measuring Test Coverage per Endpoint in Rails
euglena1215
1
430
初めてrails/railsにバグレポートを出してみた
euglena1215
0
210
GitHub Copilot を使って自作ライブラリを作ってみよう/ Let's create your own library using GitHub Copilot!
euglena1215
0
310
Other Decks in Technology
See All in Technology
「品質とスピードはトレード・オンできる」に向き合い続けた2年半を振り返る / Quality and speed can be traded on.
mii3king
0
590
ONNX推論クレートの比較と実装奮闘記
emergent
0
290
宇宙最速のランチRecap LT会(AWS re:Invent 2024)
watany
1
200
241130紅白ぺぱ合戦LT「編集の技術」
toya524287
5
620
AWS re:Invent 2024登壇資料(GBL206-JA: Unleashing the power of generative AI on AWS for your business)
minorun365
PRO
5
200
論理レプリケーションを使ったDB統合
kkato1
0
200
品質管理チームのEMとして大事にしていること / QA EM
nihonbuson
0
690
PostgreSQL Conference Japan 2024 A4 Comparison of column-oriented access methods
nori_shinoda
0
130
知らない景色を見に行こう チャンスを掴んだら道が開けたマネジメントの旅 / Into the unknown~My management journey~
kakehashi
9
1.1k
プロセス改善とE2E自動テストによる、プロダクトの品質向上事例
tomasagi
1
3.3k
開志専門職大学特別講義 2024 オープニング
1ftseabass
PRO
0
220
sre本読んだ感想
pisakun
0
220
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
27
2.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
The Invisible Side of Design
smashingmag
298
50k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Building Applications with DynamoDB
mza
91
6.1k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Writing Fast Ruby
sferik
627
61k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
A Philosophy of Restraint
colly
203
16k
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 ͬͯΔํ͍ͨΒ͍উखΛڭ͍͑ͯͩ͘͞ɻ