Commit Graph

5590 Commits

Author SHA1 Message Date
Xavier Noria
56832e791f let Regexp#match? be globally available
Regexp#match? should be considered to be part of the Ruby core library. We are
emulating it for < 2.4, but not having to require the extension is part of the
illusion of the emulation.
2016-10-27 09:13:55 +02:00
yui-knk
c51a9b975f Ensure #transform_values of HWIDA to return HWIDA
On Ruby 2.4, naitive `Hash#transform_values` is implemented.
`Hash#transform_values` uses an instance of Hash (`rb_hash_new`) to
collect returned values of a block.
For ensuring `#transform_values` of HWIDA to return HWIDA, we should
define `#transform_values` on HWIDA.
2016-10-26 11:18:10 +09:00
Rafael Mendonça França
c5d46a8a4e
Whitespace 2016-10-25 14:54:25 -02:00
Rafael França
3cc30db12c Merge pull request #26868 from prathamesh-sonpatki/use-hash-compact-from-ruby-24
Use Hash#compact and Hash#compact! from Ruby 2.4
2016-10-24 23:56:09 -02:00
Prathamesh Sonpatki
69a3fa1efc
Use Hash#compact and Hash#compact! from Ruby 2.4
- Ruby 2.4 has added Hash#compact and Hash#compact! so we can use it
  now.
- Reference: https://bugs.ruby-lang.org/issues/11818 and https://bugs.ruby-lang.org/issues/12863.
2016-10-23 20:54:39 +05:30
claudiob
fbda46758b Revert #26826 and add documentation
This reverts commit a01cf703 as explained in the comment to #26826:

Realized that this PR caused the following warning in Travis CI:

```
/home/travis/build/rails/rails/activesupport/lib/active_support/dependencies.rb:293: warning: loading in progress, circular require considered harmful - /home/travis/build/rails/rails/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb
```

Indeed, `active_support/core_ext/hash/indifferent_access.rb` **needs** to require `active_support/hash_with_indifferent_access.rb` in order to access the class `ActiveSupport::HashWithIndifferentAccess`.

The other way around, though, is not _strictly_ required, unless someone tries (like I did in the [gist above](https://gist.github.com/claudiob/43cc7fe77ff95951538af2825a71e5ec)) to use `ActiveSupport::HashWithIndifferentAccess` by only requiring `active_support/hash_with_indifferent_access.rb` without first requiring `active_support/core_ext/hash/indifferent_access.rb`.

I think the solution to this is to revert this PR and instead change the documentation to explicitly state that **developers should not require 'active_support/hash_with_indifferent_access'** if all they want is to use `ActiveSupport::HashWithIndifferentAccess` – instead they should require `active_support/core_ext/hash/indifferent_access.rb`.
2016-10-21 22:55:51 -07:00
Rafael França
7bbd3e68ed Merge pull request #26843 from denisovlev/strptime_timestamps
Fix `ActiveSupport::TimeZone#strptime` cannot parse timestamps (%Q, %s)
2016-10-22 00:12:47 -03:00
Claudio B
397025db76 Merge pull request #26826 from claudiob/add-require
Add missing require in active_support/hash_with_indifferent_access.rb
2016-10-21 18:08:34 -07:00
Aaron Patterson
b6f935bbf9
Use on_load to trigger commandline processing code
We need to use on_load so that plugins will get the same functionality
2016-10-21 14:44:17 -07:00
Charles Oliver Nutter
2674392058 Additional fix for argument-splat ordering differences.
See #26854
2016-10-21 10:16:58 -05:00
Charles Oliver Nutter
5f382d41c3 Explicitly unpack the expanded args to avoid execution order diff.
In https://bugs.ruby-lang.org/issues/12860 I argue that MRI's
execution order here is incorrect. The splatting of the 'c' args
should happen before the shift, but it happens after. On JRuby, it
behaves the way you would expect, leading to the 'c' args splat
still containing the block and producing an error like "cannot
convert proc to symbol" when the send attempts to coerce
it.

This patch makes the unpacking order explicit with a multi-assign,
which behaves properly on all implementations I tested.
2016-10-21 09:33:25 -05:00
denisovlev
07ffe7a621 Fix ActiveSupport::TimeZone#strptime cannot parse timestamps (%Q, %s) 2016-10-21 13:19:08 +03:00
Andrew White
f2c6db41ba Merge pull request #26839 from renuo/fix-missing-nsec-transfer
Fix copy_time_to: Copy nsec instead of usec
2016-10-21 07:03:32 +01:00
Yves Senn
dce4751a74 doc, hide non-public methods form the api docs. [ci skip]
This is a follow up to #25681, specifically this comment:
https://github.com/rails/rails/pull/25681#issuecomment-238294002

The way the thread local variable is stored is an implementation detail
and subject to change. It makes no sense to only generate a reader or
writer as you'd have to know where to read from or where it writes to.
2016-10-20 21:21:55 +02:00
Josua Schmid
fc72d6815a
Fix copy_time_to: Copy nsec instead of usec
`copy_time_to` is a helper function for date and time calculations.
It's being used by `prev_week`, `next_week` and `prev_weekday` to keep
the time fraction when jumping around between days.

Previously the nanoseconds part was lost during the operation. This
lead to problems in practice if you were using the `end_of_day`
calculation. Resulting in the time fraction of `end_of_day` not being
the same as next week's `end_of_day`.

With this fix `copy_time_to` doesn't forget the `nsec` digits.
2016-10-20 10:49:59 +02:00
claudiob
a01cf703e2 Add missing require 2016-10-19 11:48:43 -07:00
Rafael Mendonça França
bd8b50d2e5
Add comment to remove code when we are in Ruby 2.4 2016-10-14 23:57:03 -03:00
Jesús Burgos
e84ed4fd17 Use built-in #transform_values when available.
The methods Hash#transform_values and Hash#transform_values! have been
implemented in Ruby and they'll be available as part of the standard
library.

Here's the link to the discussion in Ruby's issue tracker:
https://bugs.ruby-lang.org/issues/12512

These methods are implemented in C so they're expected to perform
better.
2016-10-14 14:27:27 +02:00
Rafael França
3c8f26ac14 Merge pull request #26531 from y-yagi/remove_unused_benchmark
remove unused require `benchmark`
2016-10-10 22:04:00 -03:00
Matthew Draper
cb0452e9a5 Fixnum and Bignum are deprecated in Ruby trunk
https://bugs.ruby-lang.org/issues/12739
2016-10-08 08:13:11 +10:30
Matthew Draper
0464b728e2 Merge pull request #26359 from maclover7/jm-speed-up-time
Speed up Time.zone.now
2016-10-06 02:35:35 +10:30
Matthew Draper
4d6feef792 Merge pull request #26684 from matthewd/executor-serial
Avoid bumping the class serial when invoking executor
2016-10-05 05:23:48 +10:30
Matthew Draper
6ecb14715e Merge pull request #26686 from matthewd/deprecation-caller
Correct caller tracking in delegated deprecation methods
2016-10-05 05:23:20 +10:30
Matthew Draper
e8b36e7711 Avoid bumping the class serial when invoking executor 2016-10-03 13:35:51 +10:30
Jon Moss
353122c9da Speed up Time.zone.now
@amatsuda, during his RailsConf talk this past year, presented a
benchmark that showed `Time.zone.now` (an Active Support joint)
performing 24.97x slower than Ruby's `Time.now`. Rails master appears to
be a _bit_ faster than that, currently clocking in at 18.25x slower than
`Time.now`. Here's the exact benchmark data for that:

```
Warming up --------------------------------------
            Time.now   127.923k i/100ms
       Time.zone.now    10.275k i/100ms
Calculating -------------------------------------
            Time.now      1.946M (± 5.9%) i/s -      9.722M in   5.010236s
       Time.zone.now    106.625k (± 4.3%) i/s -    534.300k in   5.020343s

Comparison:
            Time.now:  1946220.1 i/s
       Time.zone.now:   106625.5 i/s - 18.25x slower
```

What if I told you we could make `Time.zone.now` _even_ faster? Well,
that's exactly what this patch accomplishes. When creating `ActiveSupport::TimeWithZone`
objects, we try to convert the provided time to be in a UTC format. All
this patch does is, in the method where we convert a provided time to
UTC, check if the provided time is already UTC, and is a `Time` object
and then return early if that is the case, This sidesteps having to continue on,
and create a new `Time` object from scratch. Here's the exact benchmark
data for my patch:

```
Warming up --------------------------------------
            Time.now   124.136k i/100ms
       Time.zone.now    26.260k i/100ms
Calculating -------------------------------------
            Time.now      1.894M (± 6.4%) i/s -      9.434M in   5.000153s
       Time.zone.now    301.654k (± 4.3%) i/s -      1.523M in   5.058328s

Comparison:
            Time.now:  1893958.0 i/s
       Time.zone.now:   301653.7 i/s - 6.28x slower
```

With this patch, we go from `Time.zone.now` being 18.25x slower than
`Time.now` to only being 6.28x slower than `Time.now`. I'd obviously love some
verification on this patch, since these numbers sound pretty interesting... :)

This is the benchmark-ips report I have been using while working on this:

```ruby
require 'benchmark/ips'

Time.zone = 'Eastern Time (US & Canada)'

Benchmark.ips do |x|
  x.report('Time.now') {
    Time.now
  }

  x.report('Time.zone.now') {
    Time.zone.now
  }

  x.compare!
end
```

cc @amatsuda
cc performance folks @tenderlove and @schneems

![Pretty... pretty... pretty good.](https://media.giphy.com/media/bWeR8tA1QV4cM/giphy.gif)
2016-10-02 15:12:46 -04:00
Matthew Draper
62ed56135b Correct caller tracking in delegated deprecation methods 2016-10-03 05:22:28 +10:30
Andrew White
9128ba5cd4 Cache to_time to improve performance when comparing
In #25880 we tried to cache localtime to fix the performance
regression but that proved to be difficult due to the fact that
localtime/getlocal can take a utc_offset argument. We tried
caching based on the argument but since the argument can be nil
sometimes that meant that if the TZ environment variable changed
then the cached value for nil became invalid. By moving the
caching to DateAndTime#compatibility we don't have to worry about
arguments since it doesn't take any.

There is a possible edge condition where preserve_timezone is set
to false and the system timezone changes then it could result in
a cached value being incorrect but the only way to fix this would
be to remove all caching and live with the performance issue.
2016-10-02 17:15:44 +01:00
Andrew White
bd8f0871c2 Revert "Merge pull request #25880 from ryandv/fix_performance_regression_in_timewithzone_to_time"
Turns out trying to cache on localtime with arguments is too hard
so we'll do it on DateAndTime::Compatibility#to_time instead.

This reverts commit 3132fa6b7d9585e04eb44b25b55d298391b040b5, reversing
changes made to 6949f8e5e7dc901d4e04ebab6c975afb33ca44c9.
2016-10-02 17:02:27 +01:00
Andrew White
6c1dac00df Revert "Merge pull request #26677 from tbalthazar/26644"
Turns out trying to cache on localtime with arguments is too hard
so we'll do it on DateAndTime::Compatibility#to_time instead.

This reverts commit 9ce2d1b1a43fc4ef3db59849b7412d30583a4074, reversing
changes made to 53ede1aff2025d4391d0e05ba471fdaf3110a99c.
2016-10-02 17:00:18 +01:00
Andrew White
9ce2d1b1a4 Merge pull request #26677 from tbalthazar/26644
Fix `ActiveSupport::TimeWithZone#localtime`
2016-10-01 21:30:02 +01:00
Thomas Balthazar
607a6c7a9a Fix ActiveSupport::TimeWithZone#localtime
Previously memoization in `localtime` wasn't taking the `utc_offset`
parameter into account when returning a cached value. It now caches the
computed value depending on the `utc_offset` parameter, e.g:

    Time.zone = "US/Eastern"

    t = Time.zone.local(2016,5,2,11)
    # => Mon, 02 May 2016 11:00:00 EDT -04:00

    t.localtime(-7200)
    # => 2016-05-02 13:00:00 -0200

    t.localtime(-3600)
    # => 2016-05-02 14:00:00 -0100
2016-10-01 13:38:43 +02:00
Matthew Draper
871ca21f6a Tighten the backtrace pollution from passing through callbacks
Callbacks are everywhere, so it's better if we can avoid making a mess
of the backtrace just because we've passed through a callback hook.

I'm making no effort to the before/after invocations: those only affect
backtraces while they're running. The calls that matter are the ones
that remain on the call stack after run_callbacks yields: around
callbacks, and internal book-keeping around the before/afters.
2016-09-30 06:57:43 +09:30
Akira Matsuda
b18f8b9d77 Merge pull request #26402 from mtsmfm/remove-dead-constants
Remove dead constants
2016-09-29 18:52:39 +09:00
Jon Moss
c93b80d53d Merge pull request #26654 from Neodelf/activesupport_1
[ci skip] Remove not necessary whitespace
2016-09-28 17:02:22 -04:00
Andrey Molchanov
1ba3ee4dd1 [ci skip] Use class name instead of path to file 2016-09-28 23:31:54 +03:00
Andrey Molchanov
05eb2c0835 [ci skip] Remove not necessary whitespace 2016-09-28 23:24:26 +03:00
yuuji.yaginuma
34a313aa35 fix typo in DateAndTime::Calculations#all_week doc [ci skip]
`Date.week_start` does not exist. `Date.beginning_of_week` seems to be correct.
Ref: #5339
2016-09-27 12:23:52 +09:00
Kasper Timm Hansen
0dfc467587 fffffff, Add code missing in 29f0fbd 2016-09-25 20:38:12 +02:00
Kasper Timm Hansen
29f0fbd5db Revise setting of run_with_rails_extension.
The Rails test runner supports three ways to run tests: directly, via rake, or ruby.

When Running with Ruby ala `ruby -Itest test/models/post_test.rb` our test file would
be evaluated first, requiring `test_helper` and then `active_support/testing/autorun`
that would then require the test file (which it hadn't been before) thus reevaluating
it. This caused exceptions if using Active Support's declarative syntax.

Fix this by shifting around when we set the how we're run to closer mimick the require
order.

If we're running with `bin/rails test` the test command file is run first and we then
set `run_with_rails_extension`, later we hit `active_support/testing/autorun` and do
nothing — because we've been run elsewhere.

If we at this point haven't set `run_with_rails_extension` we've been running with
`ruby` this whole time and thus we set that.

We should always trigger `Minitest.autorun` as it doesn't hurt to call it twice.

Consolidate the two methods into a single one that better brings out the intent of
why they're there.
2016-09-25 20:36:30 +02:00
Thomas Balthazar
76c2553b88 Fix ActiveSupport::TimeWithZone#in
Previously calls to `in` were being sent to the non-DST aware
method `Time#since` via `method_missing`. It is now aliased to
the DST aware `ActiveSupport::TimeWithZone#+` which handles
transitions across DST boundaries, e.g:

    Time.zone = "US/Eastern"

    t = Time.zone.local(2016,11,6,1)
    # => Sun, 06 Nov 2016 01:00:00 EDT -05:00

    t.in(1.hour)
    # => Sun, 06 Nov 2016 01:00:00 EST -05:00
2016-09-24 09:39:51 +02:00
Aaron Patterson
0bc196518a Merge pull request #26563 from knugie/fix_issue_26430
Prevent circular require of proxy_wrappers.rb, Fixes #26430
2016-09-23 11:27:04 -07:00
Vipul A M
3b0da83c81 Merge pull request #26594 from y-yagi/fix_formatting_of_define_callbacks
fix formatting of `define_callbacks` doc [ci skip]
2016-09-23 15:10:46 +05:30
yuuji.yaginuma
508edbc04f fix formatting of define_callbacks doc [ci skip]
Single backticks don't work with rdoc.
2016-09-23 18:37:45 +09:00
Richard Schneeman
bf19c2230d Merge pull request #26524 from y-yagi/add_check_of_argument
add check of argument
2016-09-22 09:29:25 -05:00
Wolfgang Teuber
b355a43f0e Prevent circular require of proxy_wrappers.rb, Fixes #26430 2016-09-21 00:40:48 +02:00
Andrey Molchanov
e1252e073a [ci skip] Fixed commas according to Oxford comma in rdoc and guides 2016-09-17 22:36:13 +03:00
yuuji.yaginuma
77b2e46df4 remove unused require benchmark
`Benchmark` was removed at 4215e9a
2016-09-17 20:15:28 +09:00
yuuji.yaginuma
97544ed177 add check of argument
`#fetch_multi` in case did not cache hit, to write a cache using the block value.
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache.rb#L383..L384

Therefore, block is a need to pass always, I think should check first.
2016-09-17 16:34:38 +09:00
yuuji.yaginuma
5de91258be fix formatting of Cache::Store#fetch [ci skip]
Single backticks don't work with rdoc.
2016-09-17 15:18:06 +09:00
Ryuta Kamizono
3464cd5c28 Fix broken comments indentation caused by rubocop auto-correct [ci skip]
All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772.
But comments was still kept absolute position. This commit aligns
comments with method definitions for consistency.
2016-09-14 18:26:32 +09:00