15 KiB
Rails 5.0.0.beta1 (December 18, 2015)
-
No changes.
-
Add thread_m/cattr_accessor/reader/writer suite of methods for declaring class and module variables that live per-thread. This makes it easy to declare per-thread globals that are encapsulated. Note: This is a sharp edge. A wild proliferation of globals is A Bad Thing. But like other sharp tools, when it's right, it's right.
Here's an example of a simple event tracking system where the object being tracked needs not pass a creator that it doesn't need itself along:
module Current thread_mattr_accessor :account thread_mattr_accessor :user
def self.reset() self.account = self.user = nil end end
class ApplicationController < ActiveController::Base before_action :set_current after_action { Current.reset }
private def set_current Current.account = Account.find(params[:account_id]) Current.user = Current.account.users.find(params[:user_id]) end end
class MessagesController < ApplicationController def create @message = Message.create!(message_params) end end
class Message < ApplicationRecord has_many :events after_create :track_created
private def track_created events.create! origin: self, action: :create end end
class Event < ApplicationRecord belongs_to :creator, class_name: 'User' before_validation { self.creator ||= Current.user } end
DHH
-
Deprecated
Module#qualified_const_
in favour of the builtin Module#const_ methods.Genadi Samokovarov
-
Deprecate passing string to define callback.
Yuichiro Kaneko
-
ActiveSupport::Cache::Store#namespaced_key
,ActiveSupport::Cache::MemCachedStore#escape_key
, andActiveSupport::Cache::FileStore#key_file_path
are deprecated and replaced withnormalize_key
that now callssuper
.ActiveSupport::Cache::LocaleCache#set_cache_value
is deprecated and replaced withwrite_cache_value
.Michael Grosser
-
Implements an evented file watcher to asynchronously detect changes in the application source code, routes, locales, etc.
This watcher is disabled by default, applications my enable it in the configuration:
# config/environments/development.rb config.file_watcher = ActiveSupport::EventedFileUpdateChecker
This feature depends on the listen gem:
group :development do gem 'listen', '~> 3.0.5' end
Puneet Agarwal and Xavier Noria
-
Added
Time.days_in_year
to return the number of days in the given year, or the current year if no argument is provided.Jon Pascoe
-
Updated
parameterize
to preserve the case of a string, optionally.Example:
parameterize("Donald E. Knuth", separator: '_') # => "donald_e_knuth" parameterize("Donald E. Knuth", preserve_case: true) # => "Donald-E-Knuth"
Swaathi Kakarla
-
HashWithIndifferentAccess.new
respects the default value or proc on objects that respond to#to_hash
..new_from_hash_copying_default
simply invokes.new
. All calls to.new_from_hash_copying_default
are replaced with.new
.Gordon Chan
-
Change Integer#year to return a Fixnum instead of a Float to improve consistency.
Integer#years returned a Float while the rest of the accompanying methods (days, weeks, months, etc.) return a Fixnum.
Before:
1.year # => 31557600.0
After:
1.year # => 31557600
Konstantinos Rousis
-
Handle invalid UTF-8 strings when HTML escaping
Use
ActiveSupport::Multibyte::Unicode.tidy_bytes
to handle invalid UTF-8 strings inERB::Util.unwrapped_html_escape
andERB::Util.html_escape_once
. Prevents user-entered input passed from a querystring into a form field from causing invalid byte sequence errors.Grey Baker
-
Update
ActiveSupport::Multibyte::Chars#slice!
to returnnil
if the arguments are out of bounds, to mirror the behavior ofString#slice!
Gourav Tiwari
-
Fix
number_to_human
so that 999999999 rounds to "1 Billion" instead of "1000 Million".Max Jacobson
-
Fix
ActiveSupport::Deprecation#deprecate_methods
to report using the current deprecator instance, where applicable.Brandon Dunne
-
Cache#fetch
instrumentation marks whether it was a:hit
.Robin Clowers
-
assert_difference
andassert_no_difference
now returns the result of the yielded block.Example:
post = assert_difference -> { Post.count }, 1 do Post.create end
Lucas Mazza
-
Short-circuit
blank?
on date and time values since they are never blank.Fixes #21657
Andrew White
-
Replaced deprecated
ThreadSafe::Cache
with its successorConcurrent::Map
now that the thread_safe gem has been merged into concurrent-ruby.Jerry D'Antonio
-
Updated Unicode version to 8.0.0
Anshul Sharma
-
number_to_currency
andnumber_with_delimiter
now accept customdelimiter_pattern
option to handle placement of delimiter, to support currency formats like INRExample:
number_to_currency(1230000, delimiter_pattern: /(\d+?)(?=(\d\d)+(\d)(?!\d))/, unit: '₹', format: "%u %n") # => '₹ 12,30,000.00'
Vipul A M
-
Deprecate
:prefix
option ofnumber_to_human_size
with no replacement.Jean Boussier
-
Fix
TimeWithZone#eql?
to properly handleTimeWithZone
created fromDateTime
: twz = DateTime.now.in_time_zone twz.eql?(twz.dup) => trueFixes #14178.
Roque Pinel
-
ActiveSupport::HashWithIndifferentAccess
select
andreject
will now return enumerator if called without block.Fixes #20095
Bernard Potocki
-
Removed
ActiveSupport::Concurrency::Latch
, superseded byConcurrent::CountDownLatch
from the concurrent-ruby gem.Jerry D'Antonio
-
Fix not calling
#default
onHashWithIndifferentAccess#to_hash
when onlydefault_proc
is set, which could raise.Simon Eskildsen
-
Fix setting
default_proc
onHashWithIndifferentAccess#dup
Simon Eskildsen
-
Fix a range of values for parameters of the Time#change
Nikolay Kondratyev
-
Add
Enumerable#pluck
to get the same values from arrays as from ActiveRecord associations.Fixes #20339.
Kevin Deisz
-
Add a bang version to
ActiveSupport::OrderedOptions
get methods which will raise anKeyError
if the value is.blank?
Before:
if (slack_url = Rails.application.secrets.slack_url).present? # Do something worthwhile else # Raise as important secret password is not specified end
After:
slack_url = Rails.application.secrets.slack_url!
Aditya Sanghi, Gaurish Sharma
-
Remove deprecated
Class#superclass_delegating_accessor
. UseClass#class_attribute
instead.Akshay Vishnoi
-
Patch
Delegator
to work with#try
.Fixes #5790.
Nate Smith
-
Add
Integer#positive?
andInteger#negative?
query methods in the vein ofFixnum#zero?
.This makes it nicer to do things like
bunch_of_numbers.select(&:positive?)
.DHH
-
Encoding
ActiveSupport::TimeWithZone
to YAML now preserves the timezone information.Fixes #9183.
Andrew White
-
Added
ActiveSupport::TimeZone#strptime
to allow parsing times as if from a given timezone.Paul A Jungwirth
-
ActiveSupport::Callbacks#skip_callback
now raises anArgumentError
if an unrecognized callback is removed.Iain Beeston
-
Added
ActiveSupport::ArrayInquirer
andArray#inquiry
.Wrapping an array in an
ArrayInquirer
gives a friendlier way to check its contents:variants = ActiveSupport::ArrayInquirer.new([:phone, :tablet]) variants.phone? # => true variants.tablet? # => true variants.desktop? # => false variants.any?(:phone, :tablet) # => true variants.any?(:phone, :desktop) # => true variants.any?(:desktop, :watch) # => false
Array#inquiry
is a shortcut for wrapping the receiving array in anArrayInquirer
.George Claghorn
-
Deprecate
alias_method_chain
in favour ofModule#prepend
introduced in Ruby 2.0.Kir Shatrov
-
Added
#without
onEnumerable
andArray
to return a copy of an enumerable without the specified elements.Todd Bealmear
-
Fixed a problem where
String#truncate_words
would get stuck with a complex string.Henrik Nygren
-
Fixed a roundtrip problem with
AS::SafeBuffer
where primitive-like strings will be dumped as primitives:Before:
YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello" YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => true YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => false YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => 1 YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => 1.1
After:
YAML.load ActiveSupport::SafeBuffer.new("Hello").to_yaml # => "Hello" YAML.load ActiveSupport::SafeBuffer.new("true").to_yaml # => "true" YAML.load ActiveSupport::SafeBuffer.new("false").to_yaml # => "false" YAML.load ActiveSupport::SafeBuffer.new("1").to_yaml # => "1" YAML.load ActiveSupport::SafeBuffer.new("1.1").to_yaml # => "1.1"
Godfrey Chan
-
Enable
number_to_percentage
to keep the number's precision by allowing:precision
to benil
.Jack Xu
-
config_accessor
became a private method, as with Ruby'sattr_accessor
.Akira Matsuda
-
AS::Testing::TimeHelpers#travel_to
now changesDateTime.now
as well asTime.now
andDate.today
.Yuki Nishijima
-
Add
file_fixture
toActiveSupport::TestCase
. It provides a simple mechanism to access sample files in your test cases.By default file fixtures are stored in
test/fixtures/files
. This can be configured per test-case using thefile_fixture_path
class attribute.Yves Senn
-
Return value of yielded block in
File.atomic_write
.Ian Ker-Seymer
-
Duplicate frozen array when assigning it to a
HashWithIndifferentAccess
so that it doesn't raise aRuntimeError
when callingmap!
on it inconvert_value
.Fixes #18550.
Aditya Kapoor
-
Add missing time zone definitions for Russian Federation and sync them with
zone.tab
file from tzdata version 2014j (latest).Andrey Novikov
-
Add
SecureRandom.base58
for generation of random base58 strings.Matthew Draper, Guillermo Iguaran
-
Add
#prev_day
and#next_day
counterparts to#yesterday
and#tomorrow
forDate
,Time
, andDateTime
.George Claghorn
-
Add
same_time
option to#next_week
and#prev_week
forDate
,Time
, andDateTime
.George Claghorn
-
Add
#on_weekend?
,#next_weekday
,#prev_weekday
methods toDate
,Time
, andDateTime
.#on_weekend?
returnstrue
if the receiving date/time falls on a Saturday or Sunday.#next_weekday
returns a new date/time representing the next day that does not fall on a Saturday or Sunday.#prev_weekday
returns a new date/time representing the previous day that does not fall on a Saturday or Sunday.George Claghorn
-
Change the default test order from
:sorted
to:random
.Rafael Mendonça França
-
Remove deprecated
ActiveSupport::JSON::Encoding::CircularReferenceError
.Rafael Mendonça França
-
Remove deprecated methods
ActiveSupport::JSON::Encoding.encode_big_decimal_as_string=
andActiveSupport::JSON::Encoding.encode_big_decimal_as_string
.Rafael Mendonça França
-
Remove deprecated
ActiveSupport::SafeBuffer#prepend
.Rafael Mendonça França
-
Remove deprecated methods at
Kernel
.silence_stderr
,silence_stream
,capture
andquietly
.Rafael Mendonça França
-
Remove deprecated
active_support/core_ext/big_decimal/yaml_conversions
file.Rafael Mendonça França
-
Remove deprecated methods
ActiveSupport::Cache::Store.instrument
andActiveSupport::Cache::Store.instrument=
.Rafael Mendonça França
-
Change the way in which callback chains can be halted.
The preferred method to halt a callback chain from now on is to explicitly
throw(:abort)
. In the past, callbacks could only be halted by explicitly providing a terminator and by having a callback match the conditions of the terminator. -
Add
ActiveSupport.halt_callback_chains_on_return_false
Setting
ActiveSupport.halt_callback_chains_on_return_false
totrue
will let an app support the deprecated way of halting Active Record, and Active Model callback chains by returningfalse
.Setting the value to
false
will tell the app to ignore anyfalse
value returned by those callbacks, and only halt the chain uponthrow(:abort)
.When the configuration option is missing, its value is
true
, so older apps ported to Rails 5.0 will not break (but display a deprecation warning). For new Rails 5.0 apps, its value is set tofalse
in an initializer, so these apps will support the new behavior by default.claudiob, Roque Pinel
-
Changes arguments and default value of CallbackChain's
:terminator
optionChains of callbacks defined without an explicit
:terminator
option will now be halted as soon as abefore_
callback throws:abort
.Chains of callbacks defined with a
:terminator
option will maintain their existing behavior of halting as soon as abefore_
callback matches the terminator's expectation.claudiob
-
Deprecate
MissingSourceFile
in favor ofLoadError
.MissingSourceFile
was just an alias toLoadError
and was not being raised inside the framework.Rafael Mendonça França
-
Add support for error dispatcher classes in
ActiveSupport::Rescuable
. Now it acts closer to Ruby's rescue.Example:
class BaseController < ApplicationController module ErrorDispatcher def self.===(other) Exception === other && other.respond_to?(:status) end end rescue_from ErrorDispatcher do |error| render status: error.status, json: { error: error.to_s } end end
Genadi Samokovarov
-
Add
#verified
and#valid_message?
methods toActiveSupport::MessageVerifier
Previously, the only way to decode a message with
ActiveSupport::MessageVerifier
was to use#verify
, which would raise an exception on invalid messages. Now#verified
can also be used, which returnsnil
on messages that cannot be decoded.Previously, there was no way to check if a message's format was valid without attempting to decode it.
#valid_message?
is a boolean convenience method that checks whether the message is valid without actually decoding it.Logan Leger
Please check 4-2-stable for previous changes.