Slide 1

Slide 1 text

TokyuRubyձٞ15ه೦ɺ RubyͷJSONγϦΞϥΠβ 15ݸղઆ TokyuRubyձٞ15 2024-09-29 OKURA Masafumi

Slide 2

Slide 2 text

15ճ։࠵ɺ ͓ΊͰͱ͏ ͍͟͝·͢ʂʂʂ

Slide 3

Slide 3 text

15

Slide 4

Slide 4 text

15ʹؔ͢Δ ༗ӹͳ࿩Λ͠·͢

Slide 5

Slide 5 text

15

Slide 6

Slide 6 text

RubyͷJSON γϦΞϥΠβ * 15

Slide 7

Slide 7 text

self.pp • ໊લɿ͓͓͘Β·͞;Έ • ॴଐɿϑϦʔϥϯε • ՝֎׆ಈɿKaigi on RailsνʔϑΦʔΨφΠβʔɺOH! MY RUBYISTS ϙουΩϟετओ࠻ͳͲ • ͦͯ͠ɿTokyuRubyձٞ14 LTԦ

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

1. ActiveModelSeri alizers https://github.com/rails-api/active_model_serializers

Slide 10

Slide 10 text

ActiveModelSerializers • ੲ͔Β͋ΔγϦΞϥΠβ • ྑ͍ॴɿΠϯλʔωοτ্ʹͨ͘͞Μ৘ใ͕͋Δ • ྑ͍ॴɿDSL͕࢖͍΍͍͢ • ѱ͍ॴɿͱͯͭ΋ͳ͘஗͍ • ѱ͍ॴɿ΍͸Γ஗͍

Slide 11

Slide 11 text

૯ධɿ ࠓ࠾༻͍͔ͨ͠ͳ ͋ʁ

Slide 12

Slide 12 text

2. Blueprinter https://github.com/procore-oss/blueprinter

Slide 13

Slide 13 text

Blueprinter • ൺֱత৽͘͠ɺൺֱత༗໊ʢελʔ਺1000௒ʣ • ྑ͍ॴɿൺֱత଎͍ • ྑ͍ॴɿREADME͕ॆ࣮͍ͯ͠Δ • ѱ͍ॴɿಠಛͳΠϯλʔϑΣʔεʢviewͱ͍͏࢓૊Έʣ • ѱ͍ॴɿϝϯςφϯε͕ඍົ

Slide 14

Slide 14 text

૯ධɿ ͜ΕΛ࢖͓͏͔ͳͱ ࢥ͍ͬͯͨ࣌ظ͕ࢲ ʹ΋͋Γ·ͨ͠

Slide 15

Slide 15 text

3. jbuilder https://github.com/rails/jbuilder

Slide 16

Slide 16 text

jbuilder • RailsͷϏϡʔʹಛԽͨ͠DSL • ྑ͍ॴɿ࠷ॳ͔Βೖ͍ͬͯΔ • ྑ͍ॴɿͬ͘͞ͱJSONΛฦ͢͜ͱ͕Ͱ͖Δ • ѱ͍ॴɿύʔγϟϧ͕஗͍ • ѱ͍ॴɿͦ΋ͦ΋DSL͕֮͑ΒΕͳ͍ʢ೉͘͠ͳ͍ʁʣ

Slide 17

Slide 17 text

૯ධɿ ͦͷDSLɺࢲ͸ ͪΐͬͱ…

Slide 18

Slide 18 text

4. jb https://github.com/amatsuda/jb

Slide 19

Slide 19 text

jb • amatsuda wareɺRailsͷϏϡʔͰී௨ͷRuby͕ॻ͚Δ • ྑ͍ॴɿΦʔόʔϔου͕খ͍͞ • ྑ͍ॴɿRubyͦͷ··ͳͷͰֶशίετ͕খ͍͞ • ѱ͍ॴɿRubyͦͷ··ͳͷͰந৅౓͕௿͍

Slide 20

Slide 20 text

૯ධɿ ࣮͸݁ߏ࢖ΘΕͯ ͍ΔͬΆ͍

Slide 21

Slide 21 text

5. jsonapi- serializer https://github.com/jsonapi-serializer/jsonapi- serializer

Slide 22

Slide 22 text

jsonapi-serializer • Net fl ix/fast_jsonapiͷϑΥʔΫ • ྑ͍ॴɿJSON:API࢓༷ʹै͏ͳΒ޿͘࢖ΘΕ͍ͯΔ • ѱ͍ॴɿJSON:API࢓༷ʹै͍ͨ͘ͳ͍

Slide 23

Slide 23 text

૯ධɿ JSON:APIɺօ͞ ΜͲ͏Ͱ͔͢

Slide 24

Slide 24 text

6. panko_serializer https://github.com/yosiat/panko_serializer

Slide 25

Slide 25 text

panko_serializer • OjΛϕʔεʹC֦ுϝΠϯͰॻ͔ΕͨγϦΞϥΠβ • ྑ͍ॴɿ͢͞·͘͡଎͍ʢ࣍఺ͷ2ഒҎ্ߴ଎ʣ • ѱ͍ॴɿOj͕ඞਢ • ѱ͍ॴɿػೳ͸͋·Γଟ͘ͳ͍

Slide 26

Slide 26 text

૯ධɿ C֦ு͸ͣΔ͍ ʢϕϯνϚʔΫతʹʣ

Slide 27

Slide 27 text

7. representable https://github.com/trailblazer/representable

Slide 28

Slide 28 text

representable • Trailblazerͱ͍͏Rails֦ுϑϨʔϜϫʔΫͷҰ෦ • ྑ͍ॴɿXML΍YAML΋ग़ྗͰ͖Δ • ѱ͍ॴɿൺֱత௿଎ • ѱ͍ॴɿJSONग़ྗʹ͸multi_json͕ඞཁ

Slide 29

Slide 29 text

૯ධɿ Trailblazer޷͖ʹ ͸͍͍ͷ͔΋ʁ

Slide 30

Slide 30 text

8. primalize https://github.com/jgaskins/primalize

Slide 31

Slide 31 text

primalize • ΦϒδΣΫτΛϓϦϛςΟϒܕʹม׵͢Δͱ͍͏Ξϓϩʔν • ྑ͍ॴɿܕνΣοΫ͕Ͱ͖Δ • ѱ͍ॴɿه๏͕৑௕ • ѱ͍ॴɿ଎౓͸͋·Γ଎͘ͳ͍

Slide 32

Slide 32 text

૯ධɿ ܕνΣοΫͰ͖Δ ͷ͸ྑ͍Ͱ͢Ͷ

Slide 33

Slide 33 text

9. SimpleAMS https://github.com/vasilakis fi l/SimpleAMS

Slide 34

Slide 34 text

SimpleAMS • ActiveModelSerializersͷγϯϓϧ൛…ͳͷ͔ʁ • ྑ͍ॴɿAMSΑΓߴ଎ • ѱ͍ॴɿAMSΑΓϝϞϦফඅྔ͕ଟ͍

Slide 35

Slide 35 text

૯ධɿ γϯϓϧͱ͸

Slide 36

Slide 36 text

10. Rails https://github.com/rails/rails

Slide 37

Slide 37 text

Rails • ࣮͸Railsʹ͸ඪ४ͰγϦΞϥΠβػೳ͕ೖ͍ͬͯΔ • ྑ͍ॴɿRailsΞϓϦͳΒԿ΋Πϯετʔϧ͠ͳͯ͘Α͍ • ྑ͍ॴɿOj.optimize_rails͢ΔͱΊͪΌ଎͘ͳΔ • ѱ͍ॴɿonly, except, methodsΛ࢖ͬͯγϦΞϥΠζ࣌఺Ͱमਖ਼Ͱ͖ ͯ͠·͏ʢγϦΞϥΠβ͚ͩΛݟͯ΋࠷ऴग़ྗ͕Θ͔Βͳ͍ʣ

Slide 38

Slide 38 text

૯ධɿ ͍ͭ͜ɺಈͧ͘ʂ

Slide 39

Slide 39 text

11. Alba https://github.com/okuramasafumi/alba

Slide 40

Slide 40 text

Alba • ੿࡞ • ྑ͍ॴɿPure Rubyʹͯ͠͸ͱͯ΋଎͍ • ྑ͍ॴɿ௚ײతͳDSLʹՃ͑χονͳػೳ΋ଟ਺౥ࡌ • ѱ͍ॴɿಛʹͳ͠

Slide 41

Slide 41 text

૯ධɿ جຊతʹ͸͜ΕΛ ࢖͓͚ͬͯ͹͍͍

Slide 42

Slide 42 text

12. Alba ʢclasslessʣ https://github.com/okuramasafumi/alba/blob/main/ README.md#inline-de fi nition-with-albaserialize

Slide 43

Slide 43 text

Albaʢclasslessʣ • Alba͸Ϋϥεఆ͕ٛෆཁ • ྑ͍ॴɿίϯτϩʔϥʔͷதʹγϦΞϥΠβΛ௚ॻ͖Ͱ͖Δ • ྑ͍ॴɿϒϩοΫΛ࢖͏ͷͰɺparamsͱ͔Λ௚઀࢖͑Δ • ѱ͍ॴɿ࢖Θͳ͍΄͏͕͍͍

Slide 44

Slide 44 text

૯ධɿ ࣮͸ݸਓͰϝϯς͠ ͯΔΞϓϦͰ͸͜Ε Λ࢖͍ͬͯΔ

Slide 45

Slide 45 text

13. Alba ʢܕఆ͖ٛͭʣ https://github.com/okuramasafumi/alba/blob/main/ README.md#types

Slide 46

Slide 46 text

Albaʢܕఆ͖ٛͭʣ • AlbaͰ͸ܕఆ͕ٛͰ͖Δ • ྑ͍ॴɿܕఆ͕ٛͰ͖ΔʢͰ͖Δʣ • ѱ͍ॴɿ͔ͤͬ͘ܕఆٛΛͯ͠΋ɺTypeScriptͷܕʹ͸Өڹ͕ͳ͍

Slide 47

Slide 47 text

૯ධɿ TypeScriptͷܕ͕ ΄͍͠ΜͰ͢ΑͶ͑

Slide 48

Slide 48 text

14. Alba ʢw/ typelizerʣ https://github.com/skryukov/typelizer

Slide 49

Slide 49 text

Alba (w/ typelizer) • Albaͷܕఆٛ΍γϦΞϥΠβͷఆ͔ٛΒTypeScriptͷܕ͕ಘΒΕΔ • ྑ͍ॴɿސ٬͕ຊ౰ʹཉ͔ͬͨ͠΋ͷ • ྑ͍ॴɿݫີͳఆٛΛॻ͔ͳͯ͘΋͋Δఔ౓ܕΛ࡞ͬͯ͘ΕΔ • ѱ͍ॴɿunknown͕ଟ͘ͳΓ͕ͪ

Slide 50

Slide 50 text

૯ධɿ ଞͷਓ͕ࣗ࡞ϥΠϒ ϥϦΛ֦ுͯ͘͠Ε Δͷ͸ͱͯ΋͍͍

Slide 51

Slide 51 text

15. Alba https://github.com/okuramasafumi/alba

Slide 52

Slide 52 text

Alba • ΦνͰ͢ • ྑ͍ॴɿࣗ࡞ͳͷͰ৭ʑޠΔ͜ͱ͕͋Δ • ѱ͍ॴɿ͜ͷεϥΠυʹ͸಺༰͕ͳ͍

Slide 53

Slide 53 text

૯ධɿ ΈΜͳ࢖ͬͯ͘ Εʂʂʂ

Slide 54

Slide 54 text

͝ਗ਼ௌ ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ʂ