Rails4.2の新機能

Riding Rails: Rails 4.2.0 beta1: Active Job, Deliver Later, Adequate Record, Web Console
公式blogから。

Active Job, ActionMailer #deliver_later

Active Jobが追加。その名の通りjob que。4/4.1ぐらいから入るかもというのがようやく入ったようです。Resque, Delayed Job, Sidekiq を使ってる人はほどんど同じように使えるとのこと。
これらに比べて何がいいんだろう。
 
AMでjob queにつっこむのが AM#deliver_later ActionMailer::MessageDelivery

Notifier.welcome(User.first).deliver_later
Notifier.welcome(User.first).deliver_later(in: 1.hour)
Notifier.welcome(User.first).deliver_later(at: 10.hours.from_now)

即送信ならAM#deliver_now

Notifier.welcome(User.first).deliver_now

 
また、rails/globalid という新しい概念が取り入れられたようです。ARのobjectをjobに渡す際に一意にするためのもののようです。

Adequate Record

4.2の目玉機能。ARの改良版です。多くのクエリは倍近く早くなるというキャッシュの話。tenderloveさんが大江戸rubykaigiで話していたやつです。24分ぐらいからどうぞ。(前半は前半で面白いです) [oedo04] Keynote / @ebiltwin and @tenderlove - YouTube

テーブル山ほどあるぜーっていうプロジェクトだとどんぐらいメモリ食うかが気になるところ。
動画見直して改めて思ったのですが、Rails2.3系の頃はまぁまぁ早かったんですが、リリース毎にどんどん遅くなっていってるんですね。
今回は "Rails 4.2 Will Be the Faster Ever. " だそうです。楽しみ。

Web Console

rails/web-console を見る感じでは better-errors っぽいやつかな。
(better-errorsを初めて見たときはびびった)
viewにこう書いておくと、error時じゃなくてもconsole起動できるっぽい。

<%= console %>

Everything else

Some quick highlights from the rest of all the wonder that is Rails 4.2:

・Template digests are now automatically included when calculating etags for caching. So caches are bust when the template changes.
 fresh_when使用時にtemplateの更新有無が考慮されるようになりました。
 こちらが詳しいです。
 rails commit log流し読み(2014/08/17) - なるようになるブログ

・respond_with has moved out and into its own proper home with the responders gem.

・Support for real foreign keys! add_foreign_key/remove_foreign_key are now available in migrations.

・A ton of bug fixes and minor improvements to Active Record.

・Added config.x.whatever.you_want = true for custom configuration of your app in config/environments/*, config/application.rb, and initializers.
 namespace付で独自の設定が突っ込めると。
 こうすると

# config/environments/production.rb
config.x.payment_processing.schedule = :daily
config.x.payment_processing.retries  = 3
config.x.super_debugger              = true

 こうなる。

Rails.configuration.x.payment_processing.schedule # => :daily
Rails.configuration.x.payment_processing.retries  # => 3
Rails.configuration.x.super_debugger              # => true

・Added Rails::Application.config_for(:some_yaml) to load YAML configurations store in config/ easily.
 なるほどconfig以下のyamlがsymblle指定で取り込めると。

# config/exception_notification.yml:
production:
  url: http://127.0.0.1:8080
  namespace: my_app_production
development:
  url: http://localhost:3001
  namespace: my_app_development
 
# config/production.rb
MyApp::Application.configure do
  config.middleware.use ExceptionNotifier, config_for(:exception_notification)
end

 Ruby on Rails 4.2 Release Notes — Ruby on Rails Guides あとで読もう。

Maintenance consequences and Rails 5.0!

4.2が4系では最後のでかいリリースで、次は5だと。 Rails5はRuby 2.2のみがtarget。目下spring/summer of 2015リリース目標。