| Commit message (Collapse) | Author | Age | Files | Lines |
... | |
| | |
| | |
| | |
| | |
| | | |
"active_support/core_ext/module/aliasing" is no longer used since
#19434.
|
|\ \ \
| | | |
| | | | |
A regression in `deprecate_methods` was introduced in a982a42:
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
- Refactoring alias_chain to Module#prepend broke the possibility to deprecate class methods since the module
generated was prepended to the target's instance.
A suggestion to fix this was to use `AS#redefine_method` which would solve the
problem but with the cost of redefining directly the method.
Decided to go with the same alias_chain implementation as before instead.
- Fixes #33253
|
|\ \ \ \
| | | | |
| | | | | |
Chomp will work without checking for end of the string
|
| | | | | |
|
|/ / / /
| | | |
| | | |
| | | | |
It's not defined on JRuby and unlike monotonic time, concurrent-ruby doesn't have an cross-platform abstraction for this.
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
Ruby 2.4 has native `Regexp#match?`.
https://ruby-doc.org/core-2.4.0/Regexp.html#method-i-match-3F
Related #32034.
|
| | | |
| | | |
| | | |
| | | |
| | | | |
Rubocop warns about "Use String#end_with? instead of a regex match anchored to the end of the string",
it doesn't seem aware of the $` special variable like Performance/RegexpMatch
|
|\ \ \ \
| | | | |
| | | | | |
Remove Rubocop's comments from Rails code base
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
```
Offenses:
activesupport/lib/active_support/subscriber.rb:91:17:
C: Layout/SpaceAroundOperators: Operator = should be surrounded by a single space.
event = event_stack.pop
```
|
| | | | | |
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
We don't need to have a special subscribe method for objects. The
regular `subscribe` method is more expensive than a specialized method,
but `subscribe` should not be called frequently. If that turns out to
be a hotspot, we can introduce a specialized method. :)
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
Fanout notifier can send event objects to subscribers now. Also moved
`end` lower in the `finish!` method to guarantee that CPU time is
shorter than real time.
|
|/ / / / |
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
* Use process clock instead of Time.now
This fixes any issues with the system clock changing and also eliminates
2 object allocations per event.
* Add start! and finish! methods to the event object so we can record
more information
* Adds cpu time, idle time, and allocation count for a particular event.
Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
|
|\ \ \ \
| | | | |
| | | | | |
Turn on performance based cops
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
Use attr_reader/attr_writer instead of methods
method is 12% slower
Use flat_map over map.flatten(1)
flatten is 66% slower
Use hash[]= instead of hash.merge! with single arguments
merge! is 166% slower
See https://github.com/rails/rails/pull/32337 for more conversation
|
| | | | |
| | | | |
| | | | | |
explicit mapping for enum accepts a Hash not an Array, plus the example is using `.keys` which also exists on hash
|
|\ \ \ \ \
| |/ / / /
|/| | | |
| | | | |
| | | | | |
albertoalmagro/albertoalmagro/prefer-rails-command-over-bin-rails
Prefer rails command over bin/rails
|
| | | | |
| | | | |
| | | | |
| | | | | |
Substitutes 'in via' for 'by running'
|
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | | |
As discussed in #33203 rails command already looks for, and runs,
bin/rails if it is present.
We were mixing recommendations within guides and USAGE guidelines,
in some files we recommended using rails, in others bin/rails and
in some cases we even had both options mixed together.
|
| |/ / /
|/| | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
- There was an issue inside controller tests where order params were not respected, the reason
was because we were calling `Hash#to_query` which sorts the results lexicographically.
1e4e1b62 fixed that issue by not using `to_query` but instead a utility function provided by rack.
- However with the fix came another issue where it's now no longer possible to do this
```
post :foo, params: { user: User.first }
# Prior to the patch the controller will receive { "user" => "1" }
# Whereas now you get { "user": "#<User: ...>" }
```
The fix in this PR is to modify `Hash#to_query` to sort only when it
doesn't contain an array structure that looks something like "bar[]"
Ref https://github.com/rails/rails/pull/33341#issuecomment-404039396
|
|/ / / |
|
| | | |
|
|\ \ \
| | | |
| | | | |
Use class_eval or instance_eval when triggering lazy load hooks
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
- When lazy load hooks were triggered we were using
`Object.instance_eval` which evaluates the block in the context of
the class being passed. Most of the time that class was a
`Class`. If one wants to define a instance method on the class then
it wasn't possible.
```ruby
class A; end;
A.instance_eval do
def foo
puts 'bar'
end
end
A.new.foo #> NoMethodError: undefined method `foo`
A.foo #> bar
```
- This PR checks what object is passed when triggering the hooks and
either call `class_eval` or `instance_eval`. My rational and assumptions being
that if an instance of a class is passed, then the blocks needs to
evaluate in the context of that instance (i.e. defining a method
should only define it on that instance).
On the other hand, if a Class or Module is passed when triggering
hooks, then defining a method should define it on the class itself
- #32776 Pushed me to introduce this change
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
Firstly, increment and decrement shouldn't care about the particulars of
key expiry. They should only know that they have to pass that responsibility
on to somewhere else.
Secondly, it moves the key normalization back inside the instrumentation like
it was originally. I think that matches the original design intention or at
the very least it lets users catch haywire key truncation.
Thirdly, it moves the changelog entry to the top of the file, where new entries
go. I couldn't understand what the entry was saying so I tried to rewrite it.
|
| | | | |
|
|/ / / |
|
|\ \ \
| | | |
| | | |
| | | | |
Improve some DateAndTime calculations
|
| | | | |
|
|/ / /
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
DeepCover revealed that most of these `wday != 0 ? wday - 1 : 6`
were not entirely covered, i.e. the case of `wday == 0` was not tested:
https://deep-cover.github.io/rails-cover/activesupport/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb.html#L351
There's actually no valid reason to consider Sunday a special case,
so this commit simply reajusts the values used for calculations.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
Since it is documented in the guides
http://edgeguides.rubyonrails.org/active_support_core_extensions.html#include-questionmark-and-cover-questionmark
we can add it to API docs http://edgeapi.rubyonrails.org too.
[ci skip]
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
internal API [ci skip]
`:nodoc:` is specified, but unfortunately, it is exposed in the API doc.
http://edgeapi.rubyonrails.org/classes/Enumerable.html#method-i-_original_sum_with_required_identity
If the method of the `alias` destination is public, the specification of
`:nodoc:` does not seem to work.
|
|\ \ \
| | | |
| | | | |
Align Time.zone.at method signature with that of Time::at
|
| | | |
| | | |
| | | |
| | | | |
For parity with Ruby's Time::at
|
|/ / /
| | |
| | |
| | | |
This is unnecessary since #22269.
|
| | | |
|
|\ \ \
| | | |
| | | | |
Clearer error message in assert_changes
|
| | | |
| | | |
| | | |
| | | | |
When `to:` is passed to `assert_changes`, it now prints the well-known `"Expected: x\n Actual: y"` message.
Before, the message only contained the actual value.
|
|\ \ \ \
| | | | |
| | | | | |
Document require_dependency [ci skip]
|
| |/ / / |
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
ruby/ruby@989e07c features switching `Range#===` to use internal `r_cover_p`
instead of rubyland `include?`. This breaks expected behavior of
`ActiveSupport::CoreExt::Range` documented since at least 8b67a02.
This patch adds overrides on `Range#cover?` and `Range#===` and places all
three in a single module, `CompareWithRange`.
*Requiring core_ext/range/include_range now causes a deprecation warnning*
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
In the app I'm working on I've wished that index_by had a buddy that would
assign the hash value instead of the key multiple times.
Enter index_with. Useful when building a hash from a static list of
symbols. Before you'd do:
```ruby
POST_ATTRIBUTES.map { |attr_name| [ attr_name, public_send(attr_name) ] }.to_h
```
But now that's a little clearer and faster with:
````ruby
POST_ATTRIBUTES.index_with { |attr_name| public_send(attr_name) }
```
It's also useful when you have an enumerable that should be converted to a hash,
but you don't want to muddle the code up with the overhead that it takes to create
that hash. So before, that's:
```ruby
WEEKDAYS.each_with_object(Hash.new) do |day, intervals|
intervals[day] = [ Interval.all_day ]
end
```
And now it's just:
```ruby
WEEKDAYS.index_with([ Interval.all_day ])
```
It's also nice to quickly get a hash with either nil, [], or {} as the value.
|
|/ / /
| | |
| | |
| | | |
Fixes #32928.
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
See #29632 for details. In short, it's possible to enter `LoadError#is_missing?` when `LoadError#path` returns `nil`, leading to `path.sub` throwing an none-to-helpful `NoMethodError`.
This tiniest of patch inserts `#to_s` before the `sub` call to make sure it succeeds. Affected surface area should be just as tiny since something has already gone wrong to get us into `#is_missing?` and the current behavior when `#path` returns `nil` seems clearly not intended.
[Gannon McGibbon + Neil Souza]
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | | |
This improves the performance for the most ordinalized numbers (1st,
2nd, 3rd, etc).
```
require "benchmark/ips"
def o1(number)
abs_number = number.to_i.abs
if (11..13).include?(abs_number % 100)
"th"
else
case abs_number % 10
when 1; "st"
when 2; "nd"
when 3; "rd"
else "th"
end
end
end
def o3(number)
case number
when 1; "st"
when 2; "nd"
when 3; "rd"
when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th"
else
num_modulo = number.to_i.abs % 100
if 11 <= num_modulo && num_modulo <= 13
"th"
else
case num_modulo % 10
when 1; "st"
when 2; "nd"
when 3; "rd"
else "th"
end
end
end
end
def o4(number)
case number
when 1; "st"
when 2; "nd"
when 3; "rd"
when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th"
else
num_modulo = number.to_i.abs % 100
num_modulo %= 10 if num_modulo > 13
case num_modulo
when 1; "st"
when 2; "nd"
when 3; "rd"
else "th"
end
end
end
puts RUBY_DESCRIPTION
Benchmark.ips do |x|
x.report("orig") { o1(1); o1(2); o1(3); o1(4); o1(11); o1(111); o1(1523) }
x.report("ord3") { o3(1); o3(2); o3(3); o3(4); o3(11); o3(111); o3(1523) }
x.report("ord4") { o4(1); o4(2); o4(3); o4(4); o4(11); o4(111); o4(1523) }
x.compare!
end
```
```
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin15]
Warming up --------------------------------------
orig 25.305k i/100ms
ord3 121.146k i/100ms
ord4 124.944k i/100ms
Calculating -------------------------------------
orig 275.496k (± 2.4%) i/s - 1.392M in 5.054720s
ord3 1.649M (± 5.0%) i/s - 8.238M in 5.009801s
ord4 1.700M (± 7.0%) i/s - 8.496M in 5.031646s
Comparison:
ord4: 1700059.6 i/s
ord3: 1649154.9 i/s - same-ish: difference falls within error
orig: 275496.3 i/s - 6.17x slower
```
Closes #25020.
[lvl0nax, Jeremy Daer, Ryuta Kamizono]
|
|\ \ \
| | | |
| | | | |
`SetupAndTeardown` has few caveats that breaks libraries
|
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | | |
- In #32472 I introduced a fix in order for all `after_teardown` method provided by libraries and Rails to run, even if the application's `teardown` method raised an error (That's the default minitest behavior). However this change wasn't enough and doesn't take in consideration the ancestors chain.
If a library's module containing an `after_teardown` method get included after the `SetupAndTeardown` module (one example is the [ActiveRecord::TestFixtures module](https://github.com/rails/rails/blob/7d2400ab61c8e3ed95e14d03ba3844e8ba2e36e4/activerecord/lib/active_record/fixtures.rb#L855-L856), then the ancestors of the test class would look something like
```ruby
class MyTest < ActiveSupport::TestCase
end
puts MyTest.ancestors # [MyTest, ActiveSupport::TestCase, ActiveRecord::TestFixtures, ActiveSupport::Testing::SetupAndTeardown]
```
Any class/module in the ancestors chain that are **before** the `ActiveSupport::Testing::SetupAndTeardown` will behave incorrectly:
- Their `before_setup` method will get called **after** all regular setup method
- Their `after_teardown` method won't even get called in case an exception is raised inside a regular's test `teardown`
A simple reproduction script of the problem here https://gist.github.com/Edouard-chin/70705542a59a8593f619b02e1c0a188c
- One solution to this problem is to have the `AS::SetupAndTeardown` module be the very first in the ancestors chain. By doing that we ensure that no `before_setup` / `after_teardown` get executed prior to running the teardown callbacks
|
|/ / /
| | |
| | |
| | | |
This method would be called so many times and would create so many temporary garbage Strings
|