CHANGELOG.md 9.1 KB
Newer Older
1 2 3 4
*   Fix `String#safe_constantize` throwing a `LoadError` for incorrectly cased constant references.

    *Keenan Brock*

5 6 7 8 9 10
*   Preserve key order passed to `ActiveSupport::CacheStore#fetch_multi`.

    `fetch_multi(*names)` now returns its results in the same order as the `*names` requested, rather than returning cache hits followed by cache misses.

    *Gannon McGibbon*

11 12 13 14
*   If the same block is `included` multiple times for a Concern, an exception is no longer raised.

    *Mark J. Titorenko*, *Vlad Bokov*

15 16 17 18 19
*   Fix bug where `#to_options` for `ActiveSupport::HashWithIndifferentAccess`
    would not act as alias for `#symbolize_keys`.

    *Nick Weiland*

20 21 22 23
*   Improve the logic that detects non-autoloaded constants.

    *Jan Habermann*, *Xavier Noria*

24 25 26 27 28
*   Deprecate `ActiveSupport::Multibyte::Unicode#pack_graphemes(array)` and `ActiveSuppport::Multibyte::Unicode#unpack_graphemes(string)`
    in favor of `array.flatten.pack("U*")` and `string.scan(/\X/).map(&:codepoints)`, respectively.

    *Francesco Rodríguez*

29 30 31 32
*   Deprecate `ActiveSupport::Multibyte::Chars.consumes?` in favor of `String#is_utf8?`.

    *Francesco Rodríguez*

33 34 35 36 37 38 39 40 41
*   Fix duration being rounded to a full second.
    ```
      time = DateTime.parse("2018-1-1")
      time += 0.51.seconds
    ```
    Will now correctly add 0.51 second and not 1 full second.

    *Edouard Chin*

42 43 44 45 46
*   Deprecate `ActiveSupport::Multibyte::Unicode#normalize` and `ActiveSuppport::Multibyte::Chars#normalize`
    in favor of `String#unicode_normalize`

    *Francesco Rodríguez*

47 48 49 50 51
*   Deprecate `ActiveSupport::Multibyte::Unicode#downcase/upcase/swapcase` in favor of
    `String#downcase/upcase/swapcase`.

    *Francesco Rodríguez*

52 53 54 55
*   Add `ActiveSupport::ParameterFilter`.

    *Yoshiyuki Kinjo*

56 57 58 59 60
*   Rename `Module#parent`, `Module#parents`, and `Module#parent_name` to
    `module_parent`, `module_parents`, and `module_parent_name`.

    *Gannon McGibbon*

61 62 63 64
*   Deprecate the use of `LoggerSilence` in favor of `ActiveSupport::LoggerSilence`

    *Edouard Chin*

65 66 67 68
*   Deprecate using negative limits in `String#first` and `String#last`.

    *Gannon McGibbon*, *Eric Turner*

69 70 71 72 73
*   Fix bug where `#without` for `ActiveSupport::HashWithIndifferentAccess` would fail
    with symbol arguments

    *Abraham Chan*

74 75 76 77 78
*   Treat `#delete_prefix`, `#delete_suffix` and `#unicode_normalize` results as non-`html_safe`.
    Ensure safety of arguments for `#insert`, `#[]=` and `#replace` calls on `html_safe` Strings.

    *Janosch Müller*

79 80
*   Changed `ActiveSupport::TaggedLogging.new` to return a new logger instance instead
    of mutating the one received as parameter.
81 82 83

    *Thierry Joyal*

84 85 86 87 88 89
*   Define `unfreeze_time` as an alias of `travel_back` in `ActiveSupport::Testing::TimeHelpers`.

    The alias is provided for symmetry with `freeze_time`.

    *Ryan Davidson*

X
Xavier Noria 已提交
90 91 92 93 94 95 96 97 98
*   Add support for tracing constant autoloads. Just throw

        ActiveSupport::Dependencies.logger = Rails.logger
        ActiveSupport::Dependencies.verbose = true

    in an initializer.

    *Xavier Noria*

R
Ryuta Kamizono 已提交
99
*   Maintain `html_safe?` on html_safe strings when sliced.
100 101 102 103

        string = "<div>test</div>".html_safe
        string[-1..1].html_safe? # => true

R
Ryuta Kamizono 已提交
104
    *Elom Gomez*, *Yumin Wong*
105

B
bogdanvlviv 已提交
106 107 108 109 110 111 112 113 114 115 116
*   Add `Array#extract!`.

    The method removes and returns the elements for which the block returns a true value.
    If no block is given, an Enumerator is returned instead.

        numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
        odd_numbers = numbers.extract! { |number| number.odd? } # => [1, 3, 5, 7, 9]
        numbers # => [0, 2, 4, 6, 8]

    *bogdanvlviv*

117 118 119 120 121 122 123
*   Support not to cache `nil` for `ActiveSupport::Cache#fetch`.

        cache.fetch('bar', skip_nil: true) { nil }
        cache.exist?('bar') # => false

    *Martin Hong*

A
Aaron Patterson 已提交
124
*   Add "event object" support to the notification system.
A
Aaron Patterson 已提交
125
    Before this change, end users were forced to create hand made artisanal
A
Aaron Patterson 已提交
126 127 128 129 130
    event objects on their own, like this:

        ActiveSupport::Notifications.subscribe('wait') do |*args|
          @event = ActiveSupport::Notifications::Event.new(*args)
        end
131

A
Aaron Patterson 已提交
132 133 134
        ActiveSupport::Notifications.instrument('wait') do
          sleep 1
        end
135

A
Aaron Patterson 已提交
136 137 138 139 140 141 142 143 144
        @event.duration # => 1000.138

    After this change, if the block passed to `subscribe` only takes one
    parameter, the framework will yield an event object to the block.  Now
    end users are no longer required to make their own:

        ActiveSupport::Notifications.subscribe('wait') do |event|
          @event = event
        end
145

A
Aaron Patterson 已提交
146 147 148
        ActiveSupport::Notifications.instrument('wait') do
          sleep 1
        end
149

A
Aaron Patterson 已提交
150 151 152 153 154 155 156 157
        p @event.allocations # => 7
        p @event.cpu_time    # => 0.256
        p @event.idle_time   # => 1003.2399

    Now you can enjoy event objects without making them yourself.  Neat!

    *Aaron "t.lo" Patterson*

R
Ryuta Kamizono 已提交
158
*   Add cpu_time, idle_time, and allocations to Event.
159 160 161

    *Eileen M. Uchitelle*, *Aaron Patterson*

K
Kasper Timm Hansen 已提交
162 163 164 165 166 167 168 169 170 171
*   RedisCacheStore: support key expiry in increment/decrement.

    Pass `:expires_in` to `#increment` and `#decrement` to set a Redis EXPIRE on the key.

    If the key is already set to expire, RedisCacheStore won't extend its expiry.

        Rails.cache.increment("some_key", 1, expires_in: 2.minutes)

    *Jason Lee*

R
Ryuta Kamizono 已提交
172
*   Allow `Range#===` and `Range#cover?` on Range.
U
utilum 已提交
173 174 175 176 177 178 179 180 181 182

    `Range#cover?` can now accept a range argument like `Range#include?` and
    `Range#===`. `Range#===` works correctly on Ruby 2.6. `Range#include?` is moved
    into a new file, with these two methods.

    *Requiring active_support/core_ext/range/include_range is now deprecated.*
    *Use `require "active_support/core_ext/range/compare_range"` instead.*

    *utilum*

183 184 185 186 187 188 189 190 191 192 193
*   Add `index_with` to Enumerable.

    Allows creating a hash from an enumerable with the value from a passed block
    or a default argument.

        %i( title body ).index_with { |attr| post.public_send(attr) }
        # => { title: "hey", body: "what's up?" }

        %i( title body ).index_with(nil)
        # => { title: nil, body: nil }

194
    Closely linked with `index_by`, which creates a hash where the keys are extracted from a block.
195 196 197

    *Kasper Timm Hansen*

198
*   Fix bug where `ActiveSupport::Timezone.all` would fail when tzinfo data for
199
    any timezone defined in `ActiveSupport::TimeZone::MAPPING` is missing.
200 201 202

    *Dominik Sander*

203 204 205 206 207
*   Redis cache store: `delete_matched` no longer blocks the Redis server.
    (Switches from evaled Lua to a batched SCAN + DEL loop.)

    *Gleb Mazovetskiy*

208 209 210 211 212 213 214
*   Fix bug where `ActiveSupport::Cache` will massively inflate the storage
    size when compression is enabled (which is true by default). This patch
    does not attempt to repair existing data: please manually flush the cache
    to clear out the problematic entries.

    *Godfrey Chan*

215
*   Fix bug where `URI.unescape` would fail with mixed Unicode/escaped character input:
216 217 218 219 220 221 222

        URI.unescape("\xe3\x83\x90")  # => "バ"
        URI.unescape("%E3%83%90")  # => "バ"
        URI.unescape("\xe3\x83\x90%E3%83%90")  # => Encoding::CompatibilityError

    *Ashe Connor*, *Aaron Patterson*

223 224 225 226 227
*   Add `before?` and `after?` methods to `Date`, `DateTime`,
    `Time`, and `TimeWithZone`.

    *Nick Holden*

228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
*   `ActiveSupport::Inflector#ordinal` and `ActiveSupport::Inflector#ordinalize` now support
    translations through I18n.

        # locale/fr.rb

        {
          fr: {
            number: {
              nth: {
                ordinals: lambda do |_key, number:, **_options|
                  if number.to_i.abs == 1
                    'er'
                  else
                    'e'
                  end
                end,

                ordinalized: lambda do |_key, number:, **_options|
                  "#{number}#{ActiveSupport::Inflector.ordinal(number)}"
                end
              }
            }
          }
        }


    *Christian Blais*

256 257
*   Add `:private` option to ActiveSupport's `Module#delegate`
    in order to delegate methods as private:
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273

        class User < ActiveRecord::Base
          has_one :profile
          delegate :date_of_birth, to: :profile, private: true

          def age
            Date.today.year - date_of_birth.year
          end
        end

        # User.new.age  # => 29
        # User.new.date_of_birth
        # => NoMethodError: private method `date_of_birth' called for #<User:0x00000008221340>

    *Tomas Valent*

274 275 276 277 278
*   `String#truncate_bytes` to truncate a string to a maximum bytesize without
    breaking multibyte characters or grapheme clusters like 👩‍👩‍👦‍👦.

    *Jeremy Daer*

279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
*   `String#strip_heredoc` preserves frozenness.

        "foo".freeze.strip_heredoc.frozen?  # => true

    Fixes that frozen string literals would inadvertently become unfrozen:

        # frozen_string_literal: true

        foo = <<-MSG.strip_heredoc
          la la la
        MSG

        foo.frozen?  # => false !??

    *Jeremy Daer*

K
Kasper Timm Hansen 已提交
295
*   Rails 6 requires Ruby 2.5.0 or newer.
J
Jeremy Daer 已提交
296

K
Kasper Timm Hansen 已提交
297
    *Jeremy Daer*, *Kasper Timm Hansen*
J
Jeremy Daer 已提交
298

B
bogdanvlviv 已提交
299
*   Adds parallel testing to Rails.
J
Jeremy Daer 已提交
300 301 302 303

    Parallelize your test suite with forked processes or threads.

    *Eileen M. Uchitelle*, *Aaron Patterson*
E
eileencodes 已提交
304

305

306
Please check [5-2-stable](https://github.com/rails/rails/blob/5-2-stable/activesupport/CHANGELOG.md) for previous changes.