aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/callbacks.rb
Commit message (Collapse)AuthorAgeFilesLines
* Update skip_after_callbacks_if_terminated documentationRafael Mendonça França2018-03-051-2/+2
| | | | | Now we always have a terminator, so we don't need to day the options only make sense when the `:terminator` options is specified.
* Remove deprecated `:if` and `:unless` string filter for callbacksRafael Mendonça França2017-10-231-33/+22
|
* [Active Support] require_relative => requireAkira Matsuda2017-10-211-8/+8
| | | | This basically reverts 8da30ad6be34339124ba4cb4e36aea260dda12bc
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-111-0/+1
|
* Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-091-0/+1
|
* [Active Support] require => require_relativeAkira Matsuda2017-07-011-8/+8
|
* Merge pull request #29595 from fatkodima/result_lambda_class_checkingRafael França2017-06-281-1/+1
|\ | | | | Remove useless class checking for `ActiveSupport::Callbacks`s result_lambda
| * Remove useless class checking for `ActiveSupport::Callbacks`s result_lambdafatkodima2017-06-271-1/+1
| |
* | Fix typo in callback deprecation messageyuuji.yaginuma2017-06-281-1/+1
| |
* | Add more explicit guidance on how to fix callback deprecationsSage Ross2017-06-231-2/+4
|/ | | | This deprecation warning message will be more useful if it indicates what the string was doing — being eval'd — and what the non-deprecated options for callback conditionals are.
* Add option for class_attribute default (#29270)David Heinemeier Hansson2017-05-291-2/+1
| | | | | | | | | | | | * Allow a default value to be declared for class_attribute * Convert to using class_attribute default rather than explicit setter * Removed instance_accessor option by mistake * False is a valid default value * Documentation
* Remove outdated commentMarion Bouguet2017-04-201-1/+0
| | | Since 3aee9126aa6309538ee64064dcabcd34d7cc7d26, this class hasn't inherited from Array.
* Also not needed on this file, call to `mattr_accessor` got removed in ↵Edouard CHIN2017-02-121-1/+0
| | | | https://github.com/rails/rails/commit/9e98f3f7e61dfce0a48948c8d296400af8bfaf21#diff-1ecd313ff0ab827af30014553cf8918dL76
* deprecate `halt_callback_chains_on_return_false` instead of ↵yuuji.yaginuma2017-02-081-13/+0
| | | | | | | | | | | | | | `halt_and_display_warning_on_return_false` `halt_and_display_warning_on_return_false` is not a public API and application is using `halt_callback_chains_on_return_false`. https://github.com/rails/rails/blob/5-0-stable/railties/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt#L29 https://github.com/rails/rails/blob/5-0-stable/activesupport/lib/active_support.rb#L86..L88 Therefore, deprecate messages should be issued for `halt_callback_chains_on_return_false` instead of `halt_and_display_warning_on_return_false`.
* Deprecate halt_and_display_warning_on_return_falseRafael Mendonça França2017-02-071-5/+12
|
* Remove deprecated behavior that halts callbacks when the return is falseRafael Mendonça França2017-02-071-24/+0
|
* Document that string in if and unless option of callbacks are deprecatedRafael Mendonça França2017-02-071-4/+4
|
* Improve the exception message to direct people to all the possible valuesRafael Mendonça França2017-02-071-1/+2
|
* Deprecate passing string to `:if` and `:unless` conditional options on ↵Ryuta Kamizono2017-02-041-0/+16
| | | | `set_callback` and `skip_callback`
* Remove deprecated passing string to define callbackRyuta Kamizono2017-02-041-6/+4
| | | | And raise `ArgumentError` when passing string to define callback.
* Support double-yield inside an around callbackMatthew Draper2016-12-151-3/+9
| | | | | | | It's questionable whether this is a good thing -- it forces any later/ inner callback to handle multiple invocations, along with the actual wrapped action. But it worked prior to 871ca21f6a1d65c0ec78cb5a9641411e2210460b, so we shouldn't break it unintentionally.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|
* Additional fix for argument-splat ordering differences.Charles Oliver Nutter2016-10-211-2/+2
| | | | See #26854
* Explicitly unpack the expanded args to avoid execution order diff.Charles Oliver Nutter2016-10-211-4/+4
| | | | | | | | | | | | | 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.
* Tighten the backtrace pollution from passing through callbacksMatthew Draper2016-09-301-134/+202
| | | | | | | | | | 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.
* fix formatting of `define_callbacks` doc [ci skip]yuuji.yaginuma2016-09-231-4/+4
| | | | Single backticks don't work with rdoc.
* Fix broken comments indentation caused by rubocop auto-correct [ci skip]Ryuta Kamizono2016-09-141-16/+16
| | | | | | 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.
* Fix broken heredoc indentation caused by rubocop auto-correctRyuta Kamizono2016-09-031-10/+10
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But heredocs was still kept absolute position. This commit aligns heredocs indentation for consistency.
* Add three new rubocop rulesRafael Mendonça França2016-08-161-2/+2
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* code gardening: removes redundant selfsXavier Noria2016-08-081-3/+3
| | | | | | | | | A few have been left for aesthetic reasons, but have made a pass and removed most of them. Note that if the method `foo` returns an array, `foo << 1` is a regular push, nothing to do with assignments, so no self required.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-560/+560
|
* modernizes hash syntax in activesupportXavier Noria2016-08-061-2/+2
|
* applies new string literal convention in activesupport/libXavier Noria2016-08-061-10/+10
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Change AS::Callback to ActiveSupport::Callbacks in doc [ci skip]Alex Kitchens2016-06-141-1/+1
|
* [ci skip] `define_model_callbacks` only exist in active model:Edouard CHIN2016-06-101-1/+6
| | | | - Also added a note when calling multiple time `define_callbacks`
* Specify that behavior will be deprecated in Rails 5.1Jon Moss2016-04-171-1/+1
|
* Replace _meth with _method to remove ambiguityScott Latham2016-03-301-3/+3
| | | | [ci skip]
* Eliminate instance level writers for class accessorsAaron Patterson2016-01-221-2/+2
| | | | | | | | | Instance level writers can have an impact on how the Active Model / Record objects are saved. Specifically, they can be used to bypass validations. This is a problem if mass assignment protection is disabled and specific attributes are passed to the constructor. CVE-2016-0753
* Deprecate passing string to define callback.yui-knk2015-12-161-1/+8
|
* nodoc for active support protected method [CI skip]Gaurav Sharma2015-10-041-3/+3
|
* Refactor AS::Callbacks halt config and fix the documentationRoque Pinel2015-10-011-7/+8
| | | | | | | | | Move from `AS::Callbacks::CallbackChain.halt_and_display_warning_on_return_false` to `AS::Callbacks.halt_and_display_warning_on_return_false` base on [this discussion](https://github.com/rails/rails/pull/21218#discussion_r39354580) Fix the documentation broken by 0a120a818d413c64ff9867125f0b03788fc306f8
* Fix the AS::Callbacks terminator regression from 4.2.3Roque Pinel2015-09-221-14/+28
| | | | | | Rails 4.2.3 AS::Callbacks will not halt chain if `false` is returned. That is the behavior of specific callbacks like AR::Callbacks and AM::Callbacks.
* Remove AS methods that are never invokedclaudiob2015-09-131-68/+6
| | | | | | | | | | | | | | | | | | | | Fixes #21122 - does not change any current behavior; simply reflects the fact that two conditions of the if/else statement are never reached. The reason is #17227 which adds a default terminator to AS::Callbacks. Therefore, even callback chains that do not define a terminator now have a terminator, and `chain_config.key?(:terminator)` is always true. Of course, if no terminator was defined, then we want this new default terminator not to do anything special. What the terminator actually does (or should do) is discussed in #21218 but the simple fact that a default terminator exists makes this current PR valid. *Note* that the conditional/simple methods have not been removed in AS::Conditionals::Filter::After because of `:skip_after_callbacks_if_terminated` which lets a user decide **not** to skip after callbacks even if the chain was terminated.
* [ci skip] Fix the AS::Callbacks terminator docsRoque Pinel2015-08-081-3/+3
| | | | | | | The second argument of the terminator lambda is no longer the result of the callback, but the result lambda. https://github.com/rails/rails/blob/3a7609e2bafee4b071fe35136274e6ccbae8cacd/activesupport/test/callbacks_test.rb#L553
* Revert "Revert "Reduce allocations when running AR callbacks.""Guo Xiang Tan2015-07-161-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit bdc1d329d4eea823d07cf010064bd19c07099ff3. Before: Calculating ------------------------------------- 22.000 i/100ms ------------------------------------------------- 229.700 (± 0.4%) i/s - 1.166k Total Allocated Object: 9939 After: Calculating ------------------------------------- 24.000 i/100ms ------------------------------------------------- 246.443 (± 0.8%) i/s - 1.248k Total Allocated Object: 7939 ``` begin require 'bundler/inline' rescue LoadError => e $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler' raise e end gemfile(true) do source 'https://rubygems.org' # gem 'rails', github: 'rails/rails', ref: 'bdc1d329d4eea823d07cf010064bd19c07099ff3' gem 'rails', github: 'rails/rails', ref: 'd2876141d08341ec67cf6a11a073d1acfb920de7' gem 'arel', github: 'rails/arel' gem 'sqlite3' gem 'benchmark-ips' end require 'active_record' require 'benchmark/ips' ActiveRecord::Base.establish_connection('sqlite3::memory:') ActiveRecord::Migration.verbose = false ActiveRecord::Schema.define do create_table :users, force: true do |t| t.string :name, :email t.boolean :admin t.timestamps null: false end end class User < ActiveRecord::Base default_scope { where(admin: true) } end admin = true 1000.times do attributes = { name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", email: "foobar@email.com", admin: admin } User.create!(attributes) admin = !admin end GC.disable Benchmark.ips(5, 3) do |x| x.report { User.all.to_a } end key = if RUBY_VERSION < '2.2' :total_allocated_object else :total_allocated_objects end before = GC.stat[key] User.all.to_a after = GC.stat[key] puts "Total Allocated Object: #{after - before}" ```
* Fix grammar. [CI SKIP]Guo Xiang Tan2015-05-191-1/+1
|
* Merge pull request #19029 from iainbeeston/skipping-undefined-callbacksRafael Mendonça França2015-04-061-5/+13
|\ | | | | Raise ArgumentError if an unrecognised callback is skipped
| * Raise ArgumentError if an unrecognised callback is skippedIain Beeston2015-04-031-5/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | At present, if you skip a callback that hasn't been defined, activesupport callbacks silently does nothing. However, it's easy to mistype the name of a callback and mistakenly think that it's being skipped, when it is not. This problem even exists in the current test suite. CallbacksTest::SkipCallbacksTest#test_skip_person attempts to skip callbacks that were never set up. This PR changes `skip_callback` to raise an `ArgumentError` if the specified callback cannot be found.
* | Merge pull request #19448 from tgxworld/fix_activesupport_callbacks_clash_on_runRafael Mendonça França2015-04-061-12/+4
|\ \ | |/ |/| Fix AS::Callbacks raising an error when `:run` callback is defined.
| * Revert "Reduce allocations when running AR callbacks."Guo Xiang Tan2015-03-221-12/+4
| | | | | | | | This reverts commit 796cab45561fce268aa74e6587cdb9cae3bb243e.