Ruby on Rails 4.1 Release Notes #8(Active Support)

Ruby on Rails 4.1 Release Notes — Ruby on Rails Guides
8章は、Active Supportです。

8 Active Support

8.1 Removals

・MultiJSONの依存を削除  Rails4は、Ruby1.9が以降が前提なので、jsonが標準添付ライブラリとして使えるため
 multi_jsonは不要となりました。
 
・encode_json
 activesupport-json_encoder gem化されています。
 
ActiveSupport::JSON::Variable
 上記のencode_jsonのメソッドを保有していたクラスです。
 
・String#encoding_aware?
 今はtrueを返しているようです。これなんだろ。
 
・Module#local_constant_names -> Module#local_constants
 
・DateTime.local_offset -> DateTime.civil_from_format
 
・core_ext/logger.rb
 
・ Time#time_with_datetime_fallback, Time#utc_time and Time#local_time
 -> Time#utc、 Time#local
・Hash#diff
 
・Date#to_time_in_current_zone -> Date#in_time_zone
 
・Proc#bind
 
・Array#uniq_by, Array#uniq_by!
 -> native Array#uniq, Array#uniq!
 
ActiveSupport::BasicObject -> ActiveSupport::ProxyObject
 
・BufferedLogger -> ActiveSupport::Logger
 
・assert_present, assert_blank methods
 -> object.blank?, assert object.present?
 

8.2 Deprecations

・Numeric#{ago,until,since,from_now}
 これは注意が必要そうです。
 i.e. 5.ago => 5.seconds.ago
 AS::Duration を利用すると問題ないとのこと。
 
・require path
 active_support/core_ext/object/to_json
 -> active_support/core_ext/object/json
 
ActiveSupport::JSON::Encoding::CircularReferenceError
 ActiveSupport.encode_big_decimal_as_string
 activesupport-json_encoder gem化のため
 
 

8.3 Notable changes

・AS のJSON encoderをJSON gemを使うように書き直しています。
 
ActiveSupport::Testing::TimeHelpers#travel, #travel_to

Time.travel 1.day
Time.travel -1.day

Time.travel 1.day do
  User.create.created_at # => 1 day from now
end

Time.travel_to Time.new(2004, 11, 24, 01, 04, 44)
Time.travel_to Date.new(2004, 11, 24)

Time.travel_to Time.new(2004, 11, 24, 01, 04, 44) do
  User.create.created_at # => 2004-11-24 01:04:44 -0500
end

test時のstabに使えるようです。
 
・ Numeric#in_milliseconds

>> 1.hour.in_milliseconds
=> 3600000

 
・Date#middle_of_day, DateTime#middle_of_day and Time#middle_of_day
 midday, noon, at_midday, at_noon and at_middle_of_day とたくさんエイリアスがあります。
 ユースケースがわかんないんですが、追加されています。

>> Time.now.middle_of_day
=> 2014-01-25 12:00:00 +0900

 
・String#remove
 String#gsub(pattern,'') のように使えます。
 
 

See Also

Ruby on Rails 4.1 Release Notes
#1(Rails4.1へのupgrade方法)
#2(Rails4.1の主な機能)
#3(Railties)
#4(Action Pack)
#5(Action Mailer)
#6(Active Record)
#7(Active Model)