1. 27 7月, 2017 1 次提交
    • A
      Fix division where a duration is the denominator · bfa878d3
      Andrew White 提交于
      PR #29163 introduced a change in behavior when a duration was
      the denominator in a calculation - this was incorrect as dividing
      by a duration should always return a `Numeric`. The behavior of
      previous versions of Rails has been restored.
      
      Fixes #29592.
      bfa878d3
  2. 24 7月, 2017 2 次提交
  3. 10 7月, 2017 1 次提交
  4. 12 6月, 2017 1 次提交
  5. 07 6月, 2017 1 次提交
    • J
      Cache: write_multi (#29366) · 2b96d582
      Jeremy Daer 提交于
      Rails.cache.write_multi foo: 'bar', baz: 'qux'
      
      Plus faster `fetch_multi` with stores that implement `write_multi_entries`.
      Keys that aren't found may be written to the cache store in one shot
      instead of separate writes.
      
      The default implementation simply calls `write_entry` for each entry.
      Stores may override if they're capable of one-shot bulk writes, like
      Redis `MSET`.
      2b96d582
  6. 06 6月, 2017 1 次提交
  7. 03 6月, 2017 1 次提交
  8. 30 5月, 2017 4 次提交
  9. 27 5月, 2017 1 次提交
    • D
      ActiveSupport::CurrentAttributes provides a thread-isolated attributes singleton (#29180) · 24a86443
      David Heinemeier Hansson 提交于
      * Add ActiveSupport::CurrentAttributes to provide a thread-isolated attributes singleton
      
      * Need to require first
      
      * Move stubs into test namespace.
      
      Thus they won't conflict with other Current and Person stubs.
      
      * End of the line for you, whitespace!
      
      * Support super in attribute methods.
      
      Define instance level accessors in an included module such that
      `super` in an overriden accessor works, akin to Active Model.
      
      * Spare users the manual require.
      
      Follow the example of concerns, autoload in the top level Active Support file.
      
      * Add bidelegation support
      
      * Rename #expose to #set. Simpler, clearer
      
      * Automatically reset every instance.
      
      Skips the need for users to actively embed something that resets
      their CurrentAttributes instances.
      
      * Fix test name; add tangible name value when blank.
      
      * Try to ensure we run after a request as well.
      
      * Delegate all missing methods to the instance
      
      This allows regular `delegate` to serve, so we don't need bidelegate.
      
      * Properly test resetting after execution cycle.
      
      Also remove the stale puts debugging.
      
      * Update documentation to match new autoreset
      24a86443
  10. 20 5月, 2017 1 次提交
    • A
      Fix implicit calculations with scalars and durations · 28938dd6
      Andrew White 提交于
      Previously calculations where the scalar is first would be converted
      to a duration of seconds but this causes issues with dates being
      converted to times, e.g:
      
          Time.zone = "Beijing"           # => Asia/Shanghai
          date = Date.civil(2017, 5, 20)  # => Mon, 20 May 2017
          2 * 1.day                       # => 172800 seconds
          date + 2 * 1.day                # => Mon, 22 May 2017 00:00:00 CST +08:00
      
      Now the `ActiveSupport::Duration::Scalar` calculation methods will try
      to maintain the part structure of the duration where possible, e.g:
      
          Time.zone = "Beijing"           # => Asia/Shanghai
          date = Date.civil(2017, 5, 20)  # => Mon, 20 May 2017
          2 * 1.day                       # => 2 days
          date + 2 * 1.day                # => Mon, 22 May 2017
      
      Fixes #29160, #28970.
      28938dd6
  11. 19 5月, 2017 3 次提交
  12. 30 4月, 2017 1 次提交
  13. 20 4月, 2017 1 次提交
  14. 15 4月, 2017 1 次提交
  15. 12 4月, 2017 1 次提交
  16. 11 4月, 2017 1 次提交
  17. 10 4月, 2017 1 次提交
  18. 26 3月, 2017 1 次提交
  19. 23 3月, 2017 2 次提交
  20. 22 3月, 2017 1 次提交
  21. 16 3月, 2017 1 次提交
  22. 15 3月, 2017 1 次提交
    • A
      Remove implicit coercion deprecation of durations · a91ea1d5
      Andrew White 提交于
      In #28204 we deprecated implicit conversion of durations to a
      numeric which represented the number of seconds in the duration
      because of unwanted side effects with calculations on durations
      and dates. This unfortunately had the side effect of forcing a
      explicit cast when configuring third-party libraries like
      expiration in Redis, e.g:
      
          redis.expire("foo", 5.minutes)
      
      To work around this we've removed the deprecation and added a
      private class that wraps the numeric and can perform calculation
      involving durations and ensure that they remain a duration
      irrespective of the order of operations.
      a91ea1d5
  23. 14 3月, 2017 1 次提交
  24. 11 3月, 2017 1 次提交
  25. 07 3月, 2017 3 次提交
  26. 06 3月, 2017 1 次提交
  27. 04 3月, 2017 4 次提交
    • A
      Add `rfc3339` aliases to `xmlschema` · f0aeecda
      Andrew White 提交于
      For naming consistency when using the RFC 3339 profile
      of ISO 8601 in applications.
      f0aeecda
    • A
      Add `Time.rfc3339` parsing method · 08e05d4a
      Andrew White 提交于
      The `Time.xmlschema` and consequently its alias `iso8601` accepts
      timestamps without a offset in contravention of the RFC 3339
      standard. This method enforces that constraint and raises an
      `ArgumentError` if it doesn't.
      08e05d4a
    • A
      Add `ActiveSupport::TimeZone.rfc3339` parsing method · f61062c7
      Andrew White 提交于
      Previously there was no way to get a RFC 3339 timestamp
      into a specific timezone without either using `parse` or
      chaining methods. The new method allows parsing directly
      into the timezone, e.g:
      
          >> Time.zone = "Hawaii"
          => "Hawaii"
          >> Time.zone.rfc3339("1999-12-31T14:00:00Z")
          => Fri, 31 Dec 1999 14:00:00 HST -10:00
      
      This new method has stricter semantics than the current
      `parse` method and will raise an `ArgumentError`
      instead of returning nil, e.g:
      
          >> Time.zone = "Hawaii"
          => "Hawaii"
          >> Time.zone.rfc3339("foobar")
          ArgumentError: invalid date
          >> Time.zone.parse("foobar")
          => nil
      
      It will also raise an `ArgumentError` when either the
      time or offset components are missing, e.g:
      
          >> Time.zone = "Hawaii"
          => "Hawaii"
          >> Time.zone.rfc3339("1999-12-31")
          ArgumentError: invalid date
          >> Time.zone.rfc3339("1999-12-31T14:00:00")
          ArgumentError: invalid date
      f61062c7
    • A
      Add `ActiveSupport::TimeZone.iso8601` parsing method · 4974b1a4
      Andrew White 提交于
      Previously there was no way to get a ISO 8601 timestamp into a specific
      timezone without either using `parse` or chaining methods. The new method
      allows parsing directly into the timezone, e.g:
      
          >> Time.zone = "Hawaii"
          => "Hawaii"
          >> Time.zone.iso8601("1999-12-31T14:00:00Z")
          => Fri, 31 Dec 1999 14:00:00 HST -10:00
      
      If the timestamp is a ISO 8601 date (YYYY-MM-DD) then the time is set
      to midnight, e.g:
      
          >> Time.zone = "Hawaii"
          => "Hawaii"
          >> Time.zone.iso8601("1999-12-31")
          => Fri, 31 Dec 1999 00:00:00 HST -10:00
      
      This new method has stricter semantics than the current `parse` method
      and will raise an `ArgumentError` instead of returning nil, e.g:
      
          >> Time.zone = "Hawaii"
          => "Hawaii"
          >> Time.zone.iso8601("foobar")
          ArgumentError: invalid date
          >> Time.zone.parse("foobar")
          => nil
      4974b1a4
  28. 02 3月, 2017 1 次提交
    • A
      Deprecate implicit coercion of `ActiveSupport::Duration` · 75924c45
      Andrew White 提交于
      Currently `ActiveSupport::Duration` implicitly converts to a seconds
      value when used in a calculation except for the explicit examples of
      addition and subtraction where the duration is the receiver, e.g:
      
          >> 2 * 1.day
          => 172800
      
      This results in lots of confusion especially when using durations
      with dates because adding/subtracting a value from a date treats
      integers as a day and not a second, e.g:
      
          >> Date.today
          => Wed, 01 Mar 2017
          >> Date.today + 2 * 1.day
          => Mon, 10 Apr 2490
      
      To fix this we're implementing `coerce` so that we can provide a
      deprecation warning with the intent of removing the implicit coercion
      in Rails 5.2, e.g:
      
          >> 2 * 1.day
          DEPRECATION WARNING: Implicit coercion of ActiveSupport::Duration
          to a Numeric is deprecated and will raise a TypeError in Rails 5.2.
          => 172800
      
      In Rails 5.2 it will raise `TypeError`, e.g:
      
          >> 2 * 1.day
          TypeError: ActiveSupport::Duration can't be coerced into Integer
      
      This is the same behavior as with other types in Ruby, e.g:
      
          >> 2 * "foo"
          TypeError: String can't be coerced into Integer
          >> "foo" * 2
          => "foofoo"
      
      As part of this deprecation add `*` and `/` methods to `AS::Duration`
      so that calculations that keep the duration as the receiver work
      correctly whether the final receiver is a `Date` or `Time`, e.g:
      
          >> Date.today
          => Wed, 01 Mar 2017
          >> Date.today + 1.day * 2
          => Fri, 03 Mar 2017
      
      Fixes #27457.
      75924c45