Rails4 Activesupport Changelog

原创文章,转载请注明来源并保留原文链接

activesupport

  • Date.beginning_of_week thread local and beginning_of_week application config option added (default is Monday).
    Pull Request #5339

    thread local并且多增加了一个配置选项,可以设置一周的起点是星期几,默认是星期一

    class Application < Rails::Application
      config.beginning_of_week = :wednesday
    end
  • An optional block can be passed to config_accessor to set its default value.
    Pull Request #7645

    config_accessor可以设置默认值:

    class User
      include ActiveSupport::Configurable
      config_accessor :hair_colors do
        [:brown, :black, :blonde, :red]
      end
    end

    User.hair_colors # => [:brown, :black, :blonde, :red]
  • An optional block can be passed to Hash#deep_merge. The block will be invoked for each duplicated key and used to resolve the conflict.
    Pull Request #7628

    Hash#deep_merge支持block:

    h1 = {x: {y: [4,5,6]}, z: [7,8,9]}
    h2 = {x: {y: [7,8,9]}, z: "xyz"}

    h1.deep_merge(h2) do |key, old, new|
      Array.wrap(old) + Array.wrap(new)
    end
    #=> {:x => {:y => [4, 5, 6, 7, 8, 9]}, :z => [7, 8, 9, "xyz"]}
  • ActiveSupport::Deprecation is now a class. It is possible to create an instance of deprecator. Backwards compatibility has been preserved.
    Pull Request #6348

    You can choose which instance of the deprecator will be used.

    deprecate :method_name, :deprecator => deprecator_instance

    You can use ActiveSupport::Deprecation in your gem.

    require 'active_support/deprecation'
    require 'active_support/core_ext/module/deprecation'

    class MyGem
      def self.deprecator
        ActiveSupport::Deprecation.new('2.0', 'MyGem')
      end

      def old_method
      end

      def new_method
      end

      deprecate :old_method => :new_method, :deprecator => deprecator
    end

    MyGem.new.old_method
    # => DEPRECATION WARNING: old_method is deprecated and will be removed from MyGem 2.0 (use new_method instead). (called from <main> at file.rb:18)
  • ERB::Util.html_escape encodes single quote as #39. Decimal form has better support in old browsers.
    Pull Request #7513
  • ActiveSupport::Callbacks: deprecate monkey patch of object callbacks. Using the #filter method.
    Pull Request #7560

https://github.com/rails/rails/blob/master/activesupport/CHANGELOG.md

Leave a Reply

Your email address will not be published. Required fields are marked *