New Features in Rails 4.2

D8cd979e90361eb5ca5414dd15b35d0f?s=47 murajun1978
February 21, 2015

New Features in Rails 4.2

D8cd979e90361eb5ca5414dd15b35d0f?s=128

murajun1978

February 21, 2015
Tweet

Transcript

  1. New Features in Rails 4.2 ୈ65ճ Rubyؔ੢ ษڧձ

  2. about me ΉΒ͡ΎΜ murajun1978 Ruby <3 <3 <3

  3. Shinosaka.rb #13 http://shinosakarb.doorkeeper.jp/events/19518 2 / 28

  4. ࿩͢͜ͱ • Active Job • Global ID • Adequate Record

    • Web Console • Foreign key support • Default Host for rails server
  5. Active Job

  6. Active Jobͱ͸ʁ queueing backends Active Job API Job adapter

  7. Job࡞੒ $ rails generate job job_name

  8. ಛఆͷΩϡʔ΁ͷJob࡞੒ $ rails generate job job_name —queue queue_name

  9. JobΛΩϡʔʹొ࿥

  10. JobͷεέδϡʔϦϯά

  11. ΞμϓλΛมߋ

  12. ར༻Ͱ͖ΔΞμϓλ http://api.rubyonrails.org/classes/ActiveJob/ QueueAdapters.html

  13. ίʔϧόοΫ • before_enqueue • around_enqueue • after_enqueue • before_perform •

    around_perform • after_perform
  14. Ωϡʔʹొ࿥͞ΕΔ࣌ʹ࣮ߦ • before_enqueue • around_enqueue • after_enqueue

  15. Job͕࣮ߦ͞ΕΔ࣌ʹ࣮ߦ • before_perform • around_perform • after_perform

  16. ྫ֎ॲཧ

  17. ඇಉظͰϝʔϧૹ৴

  18. Global ID

  19. URIʹΑΔϞσϧࢀর https://github.com/rails/globalid

  20. Global IDͷੜ੒ pry(main)> gid = post.to_gid => #<GlobalID:0x007f8ddfdb79e0 @uri=#<URI::GID gid://blog/Post/1>>

    URI͕ੜ੒͞Εͨ ActiveRecordΦϒδΣΫτ
  21. Global ID͔Β Modelͷ৘ใΛऔಘͯ͠ΈΔ gid.app #=> "blog" ɾΞϓϦέʔγϣϯ໊ ɾϞσϧ໊ gid.model_name #=>

    "Post" ɾϞσϧΫϥε gid.model_class #=> Post(id: integer, title: string, published_at: datetime …) ɾID gid.model_id #=> "1"
  22. Global ID͔ΒΦϒδΣΫτऔಘ globalid/lib/global_id/locator.rb GlobalID::Locator.locate gid => #<Post id: 1, title:

    "Rubyؔ੢" ...>
  23. Adequate Record

  24. http://tenderlovemaking.com/2014/02/19/adequaterecord-pro- like-activerecord.html

  25. ActiveRecord 2x faster ƅшƅ)ʂ

  26. Rails 4.1 SELECT "posts".* FROM "posts" WHERE "posts"."id" = 1

    LIMIT 1 SELECT "posts".* FROM "posts" WHERE "posts"."id" = 2 LIMIT 1 ৚݅ͷ஋͕มΘ͚ͬͨͩͳͷʹɺΫΤϦΩϟογϡ͞Εͯͳ͍
  27. Rails 4.2 SELECT "posts".* FROM "posts" WHERE "posts"."id" = ?

    LIMIT 1 [["id", 1]] SELECT "posts".* FROM "posts" WHERE "posts"."id" = ? LIMIT 1 [["id", 2]] Ωϟογϡ͞ΕͨΫΤϦʹ஋Λ౉͍ͯ͠Δ
  28. αϙʔτ͞Ε͍ͯΔ΋ͷ • find(id) • find_by(name: name) • find_by_name(name)

  29. Ωϟογϡ͕ద༻͞Εͳ͍৔߹ • ϞσϧʹσϑΥϧτείʔϓ͕ઃఆ͞Ε͍ͯΔ • ϞσϧͰ୯Ұςʔϒϧܧঝ (STI) ͕࢖༻͞Ε͍ͯΔ • PolymorphicΛ࢖ͬͯΔ •

    findͰ idͷ഑ྻΛ౉͢৔߹ • find(1,2) or find([1,2])
  30. Web Console

  31. ΤϥʔϖʔδͰσόοά

  32. ಛఆͷϖʔδͰσόοά

  33. ࢦఆIP͔ΒͷΈར༻͢Δ

  34. Foreign Key Support

  35. ϚΠάϨʔγϣϯͰ֎෦Ωʔ ͷ௥Ճɺ࡟আΛαϙʔτ

  36. αϙʔτ͞ΕΔΞμϓλ • mysql • mysql2 • postgresql

  37. Default Host for rails server

  38. σϑΥϧτͷϗετ͕0.0.0.0͔Β localhost(127.0.0.1)ʹมߋ ֎෦PC͔ΒΞΫηε͢Δ৔߹ rails server -b 0.0.0.0

  39. ·ͱΊ • Active Job͸όοΫΤϯυͷΩϡʔγεςϜʹ͔͔ΘΒ ͣɺಉ͡هड़Ͱॻ͚Δ͕ྑ͍ • ܁Γฦ͢όονॲཧͳͲ͸ɺsidetip΍sidekiq-schedulerΛ ࢖͏ͱྑ͍͔΋ • Global

    ID͸Active JobҎ֎Ͱ΋࢖͑ͦ͏ • Ruby on Rails 4.2 ϦϦʔεϊʔτಡ΋͏ • RailsͷContributorsʹײँ :)
  40. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠