Commit Graph

9801 Commits

Author SHA1 Message Date
Rafael Mendonça França
37fd0e7fe4
Development of Rails 8.0 starts now
🎉
2024-05-13 16:45:20 +00:00
Carlos Antonio da Silva
a6e2bb04dd
Merge pull request #51651 from heka1024/support-duration-in-xml
Support duration in `ActiveSupport::XmlMini`
2024-05-13 13:34:50 -03:00
Jean Boussier
06d3b358df Replace allocations count by GC time in request logs
Allocations count is often an interesting proxy for performance,
but not necessarily the most relevant thing to include in request
logs, given they aren't a per thread metric, so the reporting
is widely innacurate in multi-threaded environments.

Since Ruby 3.1 there is now `GC.total_time` which is a monotonically
increasing counter of time spent in GC. It still isn't really a per
thread metric, but is is more interesting because it uses the same
unit as the response time, allowing to better see when you have a GC
pause performance issue.
2024-05-08 23:02:35 +02:00
heka1024
b681bb6df2 Support duration in ActiveSupport::XmlMini 2024-05-04 21:37:45 +09:00
Rafael Mendonça França
2dc20197da
Remove unnecessary deprecation silencing in cache_store_compression_behavior.rb 2024-05-01 18:45:47 +00:00
Rafael Mendonça França
c48aab17ce
Remove deprecated ActiveSupport::Notifications::Event#children and ActiveSupport::Notifications::Event#parent_of? 2024-05-01 18:45:46 +00:00
Rafael Mendonça França
fc2dc7c8d3
Remove deprecated support to call the following methods without passing a deprecator
- `deprecate`
  - `deprecate_constant`
  - `ActiveSupport::Deprecation::DeprecatedObjectProxy.new`
  - `ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new`
  - `ActiveSupport::Deprecation::DeprecatedConstantProxy.new`
  - `assert_deprecated`
  - `assert_not_deprecated`
  - `collect_deprecations`
2024-05-01 18:45:45 +00:00
Rafael Mendonça França
c682bf2641
Remove deprecated ActiveSupport::Deprecation delegation to instance 2024-05-01 18:45:44 +00:00
Rafael Mendonça França
a45bfd9ee9
Remove deprecated SafeBuffer#clone_empty 2024-05-01 18:45:43 +00:00
Rafael Mendonça França
4d676ec0aa
Update deprecator horizon for 7.3
This change was never released on 7.1, so we can't remove it on 7.2.
2024-05-01 18:45:42 +00:00
Rafael Mendonça França
be211227a0
Remove deprecated #to_default_s from Array, Date, DateTime and Time 2024-05-01 18:45:41 +00:00
Rafael Mendonça França
c33e2d2e49
Remove deprecated support to passing Dalli::Client instances to MemCacheStore 2024-05-01 18:45:40 +00:00
Rafael Mendonça França
21f38d3d40
Remove deprecated config.active_support.use_rfc4122_namespaced_uuids 2024-05-01 18:45:37 +00:00
Rafael Mendonça França
e73e67ee99
Remove deprecated config.active_support.remove_deprecated_time_with_zone_name 2024-05-01 18:44:53 +00:00
Rafael Mendonça França
0e6859a237
Remove deprecated config.active_support.disable_to_s_conversion 2024-05-01 18:44:52 +00:00
Rafael Mendonça França
c4fdfc55fa
Remove deprecated support to bolding log text with positional boolean in ActiveSupport::LogSubscriber#color 2024-05-01 18:44:51 +00:00
Rafael Mendonça França
75981ade29
Remove deprecated constants ActiveSupport::LogSubscriber::CLEAR and ActiveSupport::LogSubscriber::BOLD 2024-05-01 18:44:50 +00:00
Rafael Mendonça França
38bfbcfbea
Remove deprecated support for config.active_support.cache_format_version = 6.1 2024-05-01 18:44:49 +00:00
Rafael Mendonça França
a3d6a9f5fc
Remove deprecated :pool_size and :pool_timeout options for the cache storage 2024-05-01 18:44:45 +00:00
Rafael Mendonça França
b1b2c6d59c
Remove deprecated support for the pre-Ruby 2.4 behavior of to_time
When `to_time_preserves_timezone` was set to `false`, `to_time`
would return a `Time` object with local timezone. This behavior
has been removed.
2024-05-01 18:44:31 +00:00
fatkodima
702638291c
Fix tests without assertions in the framework 2024-04-30 23:29:30 +00:00
Rafael Mendonça França
90b3f57f17
Merge pull request #51694 from Shopify/deduplicate-watched-files-in-FileUpdateChecker
Deduplicate watched filenames in `FileUpdateChecker`
2024-04-30 19:15:21 -03:00
Rafael Mendonça França
6a6c7e64f5
Remove configuration to control what we do with tests without assertions
This is too much complexity for something low value. Let's just always
warn when a test doesn't have any assertions.

If people want to raise an error or ignore them, they can do so by
overriding `Warning.warn`.
2024-04-30 21:43:54 +00:00
Nikita Vasilevsky
3b5ab678fc
Deduplicate watched filenames in FileUpdateChecker 2024-04-30 18:23:11 +00:00
Joshua Young
35e3ff3667
Fix minor typo in ActiveSupport::ProxyObject deprecation logs (#51688) 2024-04-29 20:50:27 -07:00
Andrew Novoselac
3fc58e52de Fix ActiveSupport::TestCase being loaded too early
rails/rails@76966f9 implemented configuration to report assertionless tests. But the configuration causes ActiveSupport::TestCase to be loaded too early in the boot process. It causes issues when other engines define load hooks on :active_support_test_case because they are run immediately. Instead, we should wrap the configuration in a load hook so it gets set at the appropriate time.
2024-04-28 18:49:44 -04:00
fatkodima
76966f9cb5 Allow assertionless tests to be reported 2024-04-26 18:24:16 +03:00
Rafael Mendonça França
9fd8b33ebb
Merge pull request #51653 from Earlopain/fixup-51619
Fix Ruby 3.4 internal frame cleaner test
2024-04-24 12:19:54 -03:00
Earlopain
13dc2e7a1c
Fix Ruby 3.4 internal frame cleaner test
Fixup for c85eca47f0d5845bb23a252748610b6cc618c673
2024-04-24 08:59:03 +02:00
heka1024
03c28c7595 Remove outdated comment 2024-04-24 14:49:24 +09:00
Rafael Mendonça França
4dbf7e3354
Merge pull request #51649 from andresakata/main
[ci skip] Use Ruby's official documentation urls
2024-04-23 18:40:11 -03:00
André Guimarães Sakata
f6cace4f83 Use Ruby's official documentation 2024-04-23 17:57:56 -03:00
Rafael Mendonça França
fa23f0fdd0
Merge pull request #51619 from Earlopain/ruby-3.4-backtraces
Filter internal frames in deprecation warnings for Ruby 3.4
2024-04-23 17:52:58 -03:00
Carlos Antonio da Silva
0927af90d1 Rename method to keep it consistent with others _parse_* versions
Follow-up of 46c41db8fd665735c72c1428a06c1d29a3ed7c36.
2024-04-23 09:35:24 -03:00
Miller
fb2e2f336f Support hexBinary format in XML 2024-04-23 21:20:53 +09:00
Rafael Mendonça França
8aa8de4991
Merge pull request #51271 from sato11/enable-compact-blank
Enable Hash#compact_blank inside ActiveSupport::LogSubscriber
2024-04-22 18:39:49 -03:00
Rafael Mendonça França
fee72c3aa0
Merge pull request #51640 from Shopify/prepend-to-include
Use `Module#include` rather than `prepend` for faster method lookup
2024-04-22 18:01:08 -03:00
Kevin Menard
8e251a0728 Use Module#include rather than prepend since we don't need prepend semantics here and include leads to faster method lookups. 2024-04-22 16:00:44 -04:00
Earlopain
ea7d3c5165
Deprecate ActiveSupport::ProxyObject
A historic leftover from when Ruby didn't have `BasicObject`
2024-04-22 18:51:38 +02:00
Earlopain
fb886ad464
Remove reference to BlankSlate
This has actually been removed from the builder gem in https://github.com/rails/builder/pull/15
Additionally, `BasicObject` will be more familiar to users.
2024-04-22 15:59:18 +02:00
fatkodima
0883ce1472 Fix ActiveSupport configurations deprecations 2024-04-21 19:36:36 +03:00
Earlopain
c85eca47f0
Filter internal frames in deprecation warnings for Ruby 3.4
Followup to #50923
2024-04-20 15:33:25 +02:00
Judeeeee
4ac5ee9350 docs: Fix ActiveSupport::TimeWithZone#change example [skip ci]
This Pull Request has been created because the documentation for  `ActiveSupport::TimeWithZone#change` wasn't correct.

The behavior of `:hour` and `:min` is different from the example in the documentation.
I checked with Rails 7.1.3.2 and all digits after nano seconds are 0.

```ruby
t = Time.zone.now   #=> Sat, 20 Apr 2024 14:55:55.688536000 JST +09:00
t.change(hour: 12)  #=> Sat, 20 Apr 2024 12:00:00.000000000 JST +09:00
t.change(min: 30)   #=> Sat, 20 Apr 2024 14:30:00.000000000 JST +09:00
```
2024-04-20 16:12:27 +09:00
Jean Boussier
aa84a783ee ruby-head: handle unused block warnings
Ref: https://bugs.ruby-lang.org/issues/15554

This new Ruby 3.4 warning is still being fined tuned to reduce false positives,
so we shouldn't fail builds on it just yet.

It however caught one mistake in the test suite which is valuable.
2024-04-17 12:24:12 +02:00
Jean Boussier
afa019835b Fix ActiveJob::EnqueueAfterTransactionCommit API
Fix: https://github.com/rails/rails/pull/51426#issuecomment-2042611790

`perform_later` is supposed to return the Job instance on success,
and `false` on error.

When the `enqueue` is automatically delayed, it's of course impossible
to predict if the actual queueing will succeed, but for backward compatibility
reasons, it's best to assume it will.

If necessary, you can hold onto the job instance and check for
`#successfully_enqueued?` after the transaction has completed.
2024-04-10 09:20:12 +02:00
Jean Boussier
cc0f0f9c44 Make ActiveSupport::BacktraceCleaner copy filters and silencers on dup and clone
Previously the copy would still share the internal silencers and filters array,
causing state to leak.
2024-03-29 12:13:32 +01:00
Damian Nelson
9bd8a621f7
Updating Astana with a Western Kazakhstan timezone
On March 1, 2024, Kazakhstan (all parts) switched to use UTC+5. This
updates Astana (captital of Kazakhstan) to use a Western Kazakhstan
TZInfo identifier.
2024-03-12 17:42:16 -07:00
Rosa Gutierrez
71a74ad035
Preserve encoding on truncate_bytes (#51313)
String.new with no arguments returns the empty string with ASCII-8BIT
encoding. Then, depending on each grapheme cluster of the string and
on the omission string, the resulting string might keep the ASCII-8BIT
encoding. With this change, we preserve the encoding of the original
string instead.

Note that String.new accepts an `encoding` keyword argument, like
```
String.new(encoding: Encoding::UTF_8)
```
However, instead of using that, we rely on `force_encoding` to set the
original encoding. This is so that String subclasses don't need to
preserve this keyword argument. For example, SafeBuffer doesn't.
Thanks to @jeremy for catching this!
2024-03-12 15:39:21 -07:00
Junichi Sato
ffbe6050b8
Enable Hash#compact_blank inside ActiveSupport::LogSubscriber
Using ActiveSupport::LogSubscriber#color inside a custom log subscriber
causes NoMethodError.

```ruby
require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "activesupport"
end

require "active_support"

class TestLogSubscriber < ActiveSupport::LogSubscriber
  attach_to :test

  def hi(event)
    info(color(event.payload[:message], GREEN))
  end

  private
    def log_exception(name, e)
      super
      raise e
    end
end

ActiveSupport::LogSubscriber.logger = ActiveSupport::Logger.new(STDOUT)
ActiveSupport::Notifications.instrument("hi.test", message: "Hello!")
```

```
/rails/activesupport/lib/active_support/log_subscriber.rb:193:in `mode_from': undefined method `compact_blank' for an instance of Hash (NoMethodError)

      modes = MODES.values_at(*options.compact_blank.keys)
                                      ^^^^^^^^^^^^^^
```

For what it's worth, I have encountered this while using kredis locally, like;

```
$ cd kredis
$ bin/console
irb(main):001> Kredis.string "mystring"
Could not log "meta.kredis" event. NoMethodError: undefined method `compact_blank' for an instance of Hash
```
2024-03-07 10:31:01 +09:00
Rafael Mendonça França
0a9ca0107c
✂️ 2024-02-27 02:16:02 +00:00
Rafael Mendonça França
88afcce1dd
Merge pull request #51198 from willnet/fix-wrong-documentation-for-logger_outputs_to
Fix documentation and sample code for `ActiveSupport::Logger.logger_outputs_to?`
2024-02-26 21:08:52 -05:00
Shinichi Maeshima
fc62f03ae3
[ci skip]Fix documentation and sample code for ActiveSupport::Logger.logger_outputs_to?
Fixed incorrect documentation for `ActiveSupport::Logger.logger_outputs_to?`. The method expects the first argument to be a Logger object and subsequent variadic arguments to be either IO objects or strings representing file paths.

Also corrected the sample code in CHANGELOG.md, which previously only passed a single argument, not reflecting the correct usage.

related PR: https://github.com/rails/rails/pull/51125
2024-02-27 10:56:53 +09:00
Rafael Mendonça França
ada3d775bd
Use Kernel#Array to wrap the default value 2024-02-27 01:37:54 +00:00
Rafael Mendonça França
d216d1ede7
Do not always mark the default translation as html safe
If the `_html` suffis isn't provided we should not mark the default
translation as html safe and escape it.
2024-02-27 01:36:40 +00:00
John Hawthorn
0f870c4354 Respect raise_on_missing_ in controller
Previously raise_on_missing_translations was not being respected in a
controller. This commit brings back the correct behaviour.
2024-02-21 13:18:58 -08:00
Rafael Mendonça França
be0661c67a
Merge pull request #51132 from tonytonyjan/docs/fix-fetch-example
Improve the example of ActiveSupport::Cache::Store#fetch
2024-02-20 18:37:44 -05:00
Jian Weihang
a8bc63af54
Improve the example of ActiveSupport::Cache::Store#fetch
The original example has race condition issue that the output of the example isn't conistent, see https://github.com/rails/rails/issues/43588.

The change improves the example by removing unnecessary thread and add detailed comments.

In the new example, there will be race condition only if `ActiveSupport::Cache::MemoryStore` took longer than 0.1 second to extend expiry but that's unlikely to happen.

Close #43588
2024-02-20 12:08:39 +08:00
Christian Schmidt
d518457ca3 Rubocop 2024-02-19 13:43:59 +01:00
Christian Schmidt
3aa7d79418 Support filenames in Logger.logger_outputs_to? 2024-02-19 13:39:48 +01:00
Jean Boussier
50daadaa71 Update test suite for compatibility with Ruby 3.4-dev
https://bugs.ruby-lang.org/issues/19117 and https://bugs.ruby-lang.org/issues/16495
slightly change how backtrace are rendered which makes a few tests fail.
2024-02-16 11:55:44 +01:00
Jean Boussier
ca6995a80c Update Method#duplicable? to be consistent with Ruby 3.4
Fix: https://github.com/rails/rails/issues/51075

`Method` and `UnboundMethod` used to raise on `#dup`, but not `#clone`,
this wasn't so much a feature, but a bug.

It was fixed in https://github.com/ruby/ruby/pull/9926.
2024-02-14 09:52:55 +01:00
Rafael Mendonça França
efa8889ad6
Merge pull request #51017 from p8/activesupport/document-time-zone-create
Improve documentation of ActiveSupport::TimeZone.create [ci-skip]
2024-02-09 18:31:27 -05:00
Jean Boussier
7025c84eda Workaround a Ruby bug that can cause a VM crash
See: https://bugs.ruby-lang.org/issues/20250

The bug exist all the way since Ruby 2.7, if you `clone` a `Proc`
object on which you already accessed `object_id`, when its clone
is GCed Ruby will crash.

By accessing the clone's `object_id` right away, we prevent the
crash.
2024-02-09 16:29:46 +01:00
Petrik
15b45953a0 Improve documentation of ActiveSupport::TimeZone.create [ci-skip]
The `create` method is currently marked as an alias of `new`. However,
because `new` is later overridden, it's no longer an alias.

This requires wrapping the `alias_method` with stopdoc/startdoc, as the
method is still marked as an alias otherwise (adding `:nodoc:` doesn't
help).

The `initialize` method has to be wrapped with stopdoc/startdoc as well,
as the `new` method will still be documented for the initialized.
Adding a `:nodoc:` instead will remove documentation for all following
methods.
2024-02-08 21:21:57 +01:00
Yasuo Honda
0c9329161c Pin minitest version to 5.21
Managed to reproduce CI failure at https://buildkite.com/rails/rails-nightly/builds/133#018d7bb8-8a32-4978-8e36-d7cb9b067813/1196-1204 . It would also reproduce against the released versions of Ruby because this is triggered by minitest v5.22.0 change. ebb468c81c

To avoid all of railties CI failures, pin minitest version to 5.21 tentatively.

* Steps to reproduce
```ruby
git clone https://github.com/rails/rails
cd rails
rm Gemfile.lock
bundle install
cd railties
bin/test test/application/test_runner_test.rb -n test_system_tests_are_not_run_with_the_default_test_command
```

* Expected behavior
It should pass.

* Actual behavior
```ruby
$ bin/test test/application/test_runner_test.rb -n test_system_tests_are_not_run_with_the_default_test_command
Run options: -n test_system_tests_are_not_run_with_the_default_test_command --seed 14574

F

Failure:
ApplicationTests::TestRunnerTest#test_system_tests_are_not_run_with_the_default_test_command [test/application/test_runner_test.rb:1191]:
Expected /0\ runs,\ 0\ assertions,\ 0\ failures,\ 0\ errors,\ 0\ skips/ to match "Nothing ran for filter: \nRunning 0 tests in a single process (parallelization threshold is 50)\nRun options: --seed 45713\n\n# Running:\n\n".

bin/test test/application/test_runner_test.rb:1179

Finished in 9.982314s, 0.1002 runs/s, 0.2004 assertions/s.
1 runs, 2 assertions, 1 failures, 0 errors, 0 skips
$
```
2024-02-06 10:52:58 +09:00
George Ma
3711c69ab0 Add :: to namespace the module we delegate "to"
Only namespace when the delegation object is a module
2024-01-31 11:35:15 +01:00
Tristan Starck
b0b481a7c4
Fix teardown callbacks (#50915)
* Switch ActiveSupport::TestCase teardown and setup callbacks to run in setup and teardown minitest lifecycle hooks.

Minitest provides `setup` and `teardown` lifecycle hooks to run code in. In general it is best practice to when defining your own test case class, to use `Minitest::TestCase.setup` and `Minitest::TestCase.teardown` instead of `before_setup` and `after_teardown`.

Per Minitest's Documentation on Lifecycle Hooks: https://docs.ruby-lang.org/en/2.1.0/MiniTest/Unit/LifecycleHooks.html
> before_setup()
> Runs before every test, before setup. This hook is meant for libraries to extend minitest. It is not meant to be used by test developers.

> after_teardown()
> Runs after every test, after teardown. This hook is meant for libraries to extend minitest. It is not meant to be used by test developers.

Since the `setup` and `teardown` ActiveSupport::TestCase callbacks are in essence user code, it makes sense to run during their corresponding Minitest Lifecycle hooks.

* Ensure test fixutres are torndown on errors in superclass after_teardown code.

By not adding wrapping the `teardown_fixtures` code, its possible that super raises an error and prevents the existing database transaction from rolling back.
`super` in general should only be calling `Minitest::Testcase.after_teardown` however, if another library were to override `Minitest::Testcase.after_teardown`, like the popular gem [rspec-mocks](https://github.com/rspec/rspec-mocks/blob/main/lib/rspec/mocks/minitest_integration.rb#L23) does, it causes all subsequent tests to retain any changes that were made to the database in the original test that errors.

* Remove unnecessary setup and teardown methods in tests

* update activesupport Changelog

* Fix linter issues in CHANGELOG

* fix tests with improper setup and teardown method definitions

* Fix final CHANGELOG lint

* Revert "Fix final CHANGELOG lint"

This reverts commit f30682eb629780862ccc63e1d3210dfe035e997e.

* Revert "fix tests with improper setup and teardown method definitions"

This reverts commit 1d5b88c8739695a4eed5c46924c9ffc6010353f5.

* Revert "Fix linter issues in CHANGELOG"

This reverts commit 60e89bd189cbcdf50d7e923a90ec5ebe1578a6e9.

* Revert "update activesupport Changelog"

This reverts commit 0f19bc324fec7a793cc34dcfede27017b5a24e46.

* Revert "Remove unnecessary setup and teardown methods in tests"

This reverts commit e5673f179ac01c814ab44017b97e7638aad6e775.

* Revert "Switch ActiveSupport::TestCase teardown and setup callbacks to run in setup and teardown minitest lifecycle hooks."

This reverts commit d08d92d86131d8643a275397d9b0c15995730a14.

* Rescue Minitest::Assertion errors in ActiveSupport::TestCase.teardown callback code to ensure all other after_teardown methods are called.

* Fix name of test class

* remove unused MyError class

* Fix module to not be in global namespace

Co-authored-by: Rafael Mendonça França <rafael@rubyonrails.org>
2024-01-30 19:05:18 -05:00
Rafael Mendonça França
316338acf7
Merge pull request #50921 from yahonda/rubygems_7386
Require 'uri' explicitly to address `NameError: uninitialized constant ToQueryTest::URI`
2024-01-30 13:48:58 -05:00
Jean Boussier
794016aad7 BacktraceCleaner silence core internal methods by default
In recent Ruby versions some pure C functions have been moved into
some semi-ruby code and now have an `<internal:something>` location.

They should be silenced like stdlib etc.
2024-01-30 13:24:50 +01:00
Yasuo Honda
33c6f0f723 Require 'uri' explicitly to address NameError: uninitialized constant ToQueryTest::URI
This commit addresses CI failure
at https://buildkite.com/rails/rails-nightly/builds/108#018d57ac-4f2a-45f1-86b9-9015a7b0a463/1165-2002

* Error addressed by this commit
```
$ ruby -v
ruby 3.4.0dev (2024-01-30T10:19:23Z master 86547fd69d) [x86_64-linux]
$ rm Gemfile.lock
$ bundle install
$ cd activesupport
$ bin/test test/core_ext/object/to_query_test.rb -n test_hash_not_sorted_lexicographically_for_nested_structure
... snip ...

E

Error:
ToQueryTest#test_hash_not_sorted_lexicographically_for_nested_structure:
NameError: uninitialized constant ToQueryTest::URI
    test/core_ext/object/to_query_test.rb:90:in `test_hash_not_sorted_lexicographically_for_nested_structure'

bin/test test/core_ext/object/to_query_test.rb:79

Finished in 0.000385s, 2597.3082 runs/s, 0.0000 assertions/s.
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
$
```

This behavior has been introduced since Ruby 3.4.0dev vendors URI from top level to `Gem::URI`
via d64d0b5423 .
Here is the RubyGems one.
https://github.com/rubygems/rubygems/pull/7386
2024-01-30 20:29:33 +09:00
Jean Boussier
8ec5219801 ActiveSupport::Delegation allow to specify the signature
When delegating known APIs, rather that to let Delegator try to
inspect the signature, or to fallback to `...`, we can directly
specify it.

This is both faster and make for nicer delegators that have
the right signature.
2024-01-25 11:51:01 +01:00
Jean Boussier
f760ccd171 ActiveSupport::Delegation optimize self.class delegation
Since `self.class` can't possible be `nil`, we can skip the
useless `nil` checks and generate more efficient code.
2024-01-25 11:51:00 +01:00
Jean Boussier
bffe05f246 Module#delegate stop accepting the private as: parameter
The feature remains usable internally, but via `ActiveSupport::Delegation`,
this way we don't allow third party use.
2024-01-25 11:51:00 +01:00
Jean Boussier
6ee0041ed2 Refactor Module#delegate inside ActiveSupport::Delegation
This allow to support some extra private features without exposing
them in `Module#delegate`.
2024-01-25 11:51:00 +01:00
Jean Boussier
ddc32f5a47 Use an anonymous block parameter in Module#delegate
`...` generates an anonymous block, it's basically a shortcut
for `*, **, &`. So to look more similar to tools that introspect
method signatures, it's best to continue to use an anonymous block.
2024-01-25 09:16:21 +01:00
Petrik de Heus
fe81d667a7
Merge pull request #50789 from p8/docs/relative-includes
Use relative includes of README's in documentation [ci-skip]
2024-01-21 18:30:07 +01:00
m-nakamura145
a5af0a9118
Add example to parts documentation [ci-skip] 2024-01-19 22:05:59 +09:00
Petrik
8565f45100 Use relative includes of README's in documentation [ci-skip]
The Rails documentation uses the `:include:` directive to inline the
README of the framework into the main documentation page. As the
README's aren't in the root directory from where SDoc is run we need to
add the framework path to the include:

    # :include: activesupport/README.md

This results in a warning when installing the gems as generating the rdoc for the gem is run from the gem/framework root:

    Couldn't find file to include 'activesupport/README.rdoc' from lib/active_support.rb

The `:include:` RDoc directive supports includes relative to the current
file as well:

    # :include: ../README.md

This makes sure it works for the Rails API docs and the separate gems.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2024-01-18 10:39:15 +01:00
Jean Boussier
4530a56e0f RateLimiting Cleanups
Followup: https://github.com/rails/rails/pull/50781

Some small issues I failed to address in the original PR.
2024-01-18 10:11:43 +01:00
Jean Boussier
b54a287f9d Ensure all Cache store have consistent TTL behavior on increment
Make sure they all increment the counter but don't update the TTL.
2024-01-17 15:40:16 +01:00
Jean Boussier
de779f2bf7 Fix ActiveSupport::Notifications.publish_event to preserve units
Ref: https://github.com/rails/rails/pull/43502
Fix: https://github.com/rails/rails/pull/50767
Fix: https://github.com/rails/rails/pull/50493

When republishing a an event into a `start, finish` tuple, we need
to convert the timestamps back into seconds.
2024-01-17 12:53:40 +01:00
Eugene Kenny
0656787be6
Merge pull request #50764 from eugeneius/syntax_error_proxy_nil_backtrace_locations
Handle nil backtrace_locations in SyntaxErrorProxy
2024-01-16 14:20:13 +00:00
Jean Boussier
946e46ebcc Modernize method missing implementations
`...` is both simpler an more correct since the keyword argument
separation.
2024-01-16 13:17:45 +01:00
Eugene Kenny
16d1351a93 Handle nil backtrace_locations in SyntaxErrorProxy 2024-01-16 01:05:53 +00:00
r-plus
38151711c8 Fix IPAddr prefix information missing when write to cache in msgpack serializer
* Save cache size by omit the prefix if unnecessary

* rename to straightforward naming.

* check the prefix directly instead of inspect

* Remove unused helper method

* add to changelog

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2024-01-15 00:40:44 -06:00
Earlopain
805fa6faf3
Fix typo in ActiveSupport changelog 2024-01-14 14:15:54 +01:00
Jonathan Hefner
aa98bc3c71 Prevent CurrentAttributes defaults from leaking
Follow-up to #50677.

Prior to this commit, all `ActiveSupport::CurrentAttributes` subclasses
stored their default values in the same `Hash`, causing default values
to leak between classes.  This commit ensures each subclass maintains a
separate `Hash`.

This commit also simplifies the resolution of default values, replacing
the `merge_defaults!` method with `resolve_defaults`.
2024-01-11 12:40:14 -06:00
Jean Boussier
4bded3c00a Module#delegate avoid creating a unique fstring for each delegator
For example:

```ruby
delegate :negative?, to: :value, as: Numeric
```

Before:

```
def negative?(&block)
  _ = @value
  _.negative?(&block)
rescue NoMethodError => e
  if _.nil? && e.name == :negative?
    raise DelegationError, "ActiveSupport::Duration#negative? delegated to @value.negative?, but @value is nil: #{self.inspect}"
  else
    raise
  end
end
```

After:

```ruby
def negative?(&block)
  _ = @value
  _.negative?(&block)
rescue NoMethodError => e
  if _.nil? && e.name == :negative?
    raise DelegationError.nil_target(:negative?, :"@value")
  else
    raise
  end
end
```

Before almost every delegator would generate a large unique string that gets interned for
the error message that is rarely if ever used.

Rather than to "hardcode" a unique string, we now only pass pre-existing symbols to
a method helper that will build the error message.

This alone saves about 160B per delegator, and the method bytecode is also marginally
smaller (but it's harder to assess how much this actually saves)
2024-01-10 19:27:50 +01:00
Jean Boussier
61b48fe76d
Merge pull request #50686 from seanpdoyle/remove-current-attributes-method-missing
Avoid definition of methods at runtime in `CurrentAttributes`
2024-01-10 09:40:09 +01:00
Sean Doyle
c8e5b0b531 Avoid definition of methods in CurrentAttributes at runtime
Replacing on the fly a `method_missing` by a generated method
sound like a nice trick, but it's not as good as it sound for
optimization, as the method will be generated by the first
request to use it, preventing the ISeq from being is shared memory.

Instead we can eagerly define a delegator when instance methods
are defined, and keep a regular `method_missing + send` for the
very rare cases not covered.

Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
2024-01-10 08:59:35 +01:00
Sean Doyle
d1d6b6bce3 Add default: support for ActiveSupport::CurrentAttributes.attribute
Extend the `.attribute` class method to accept a `:default` option for
its list of attributes:

```ruby
class Current < ActiveSupport::CurrentAttributes
  attribute :counter, default: 0
end
```

Internally, `ActiveSupport::CurrentAttributes` will maintain a
`.defaults` class attribute to determine default values during instance
initialization.
2024-01-09 19:09:57 -05:00
Sean Doyle
2cd4abcc87 Simplify CurrentAttribute.instance delegation
Follow-up to [#50676][]

Instead of relying on code generation, call a corresponding [delegate][]
method on the `.singleton_class`.

[#50676]: https://github.com/rails/rails/pull/50676
[delegate]: https://edgeapi.rubyonrails.org/classes/Module.html#method-i-delegate

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-01-09 16:54:00 -05:00
Sean Doyle
3c72983dc5 Implement CurrentAttributes#set in terms of Object#with
`CurrentAttributes` supports block-scoped overrides for its attributes
through the `#set` method. The introduction of [CurrentAttributes#set][]
predates the introduction of [Object#with][] by 6 years.

This commit changes the implementation of `#set` to delegate to `#with`.
Through that delegation, the private `#assign_attributes` and
`#compute_attributes` methods are no longer necessary.

[CurrentAttributes#set]: 2d6b02bad6/activesupport/lib/active_support/current_attributes.rb (L210)
[Object#with]: 2d6b02bad6/activesupport/lib/active_support/core_ext/object/with.rb (L26)
2024-01-09 14:34:18 -05:00
Jean Boussier
a3d05309aa Get rid of ForkTracker.check!
Now that we require Ruby 3.1, we can assume `Process._fork` is
defined on MRI, hence we can trust that our decorator will
reliably detect forks so we no longer need to check the if
the pid changed in critical spots.
2024-01-09 11:18:38 +01:00
Jean Boussier
8c7e69b79b Optimize Hash#stringify_keys
Using Symbol#name allows to hit two birds with one stone.

First it will return a pre-existing string, so will save
one allocation per key.

Second, that string will be already interned, so it will
save the internal `Hash` implementation the work of looking
up the interned strings table to deduplicate the key.

```
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-darwin21]
Warming up --------------------------------------
                to_s    17.768k i/100ms
                cond    23.703k i/100ms
Calculating -------------------------------------
                to_s    169.830k (±10.4%) i/s -    852.864k in   5.088377s
                cond    236.803k (± 7.9%) i/s -      1.185M in   5.040945s

Comparison:
                to_s:   169830.3 i/s
                cond:   236803.4 i/s - 1.39x  faster
```

```ruby
require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'benchmark-ips', require: false
end

HASH = {
  first_name: nil,
  last_name: nil,
  country: nil,
  profession: nil,
  language: nil,
  hobby: nil,
  pet: nil,
  longer_name: nil,
  occupation: nil,
  mailing_address: nil,
}.freeze

require 'benchmark/ips'

Benchmark.ips do |x|
  x.report("to_s") { HASH.transform_keys(&:to_s) }
  x.report("cond") { HASH.transform_keys { |k| Symbol === k ? k.name : k.to_s } }
  x.compare!(order: :baseline)
end
```
2024-01-08 19:19:20 +01:00
Earlopain
d96c424fab
Remove core_ext/uri.rb exception
The file was removed in da8e6f6175
2024-01-08 10:58:39 +01:00
Jonathan Hefner
3bbf21c343 Use verb form of "fallback"
"Fallback" is a noun, whereas "fall back" is a verb.
2024-01-07 17:27:23 -06:00
Jean Boussier
c0b5052d92
Merge pull request #50609 from ricardotk002/use-array-intersect
Replace usage of `Array#?` with `Array#intersect?` for efficiency
2024-01-07 21:15:56 +01:00
Sean Doyle
9e64b13d8a Yield instance to Object#with block
The introduction of the block argument means that `Object#with` can now
accept a `Symbol#to_proc` as the block argument:

```ruby
client.with(timeout: 5_000) do |c|
  c.get("/commits")
end
```
2024-01-07 20:56:33 +01:00
Jonathan Hefner
53ba75d1aa Clean up AS::NumberHelper#number_to_human doc [ci-skip] 2024-01-06 18:07:26 -06:00