Class: ActiveSupport::Callbacks::Callback
- Defined in:
- lib/active_support/callbacks.rb
Overview
:nodoc:#
Instance Attribute Summary collapse
-
#chain_config ⇒ Object
readonly
Returns the value of attribute chain_config.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#apply(callback_sequence) ⇒ Object
Wraps code with filter.
- #current_scopes ⇒ Object
- #duplicates?(other) ⇒ Boolean
- #filter ⇒ Object
-
#initialize(name, filter, kind, options, chain_config) ⇒ Callback
constructor
A new instance of Callback.
- #matches?(_kind, _filter) ⇒ Boolean
- #merge_conditional_options(chain, if_option:, unless_option:) ⇒ Object
- #raw_filter ⇒ Object
Constructor Details
#initialize(name, filter, kind, options, chain_config) ⇒ Callback
Returns a new instance of Callback.
297 298 299 300 301 302 303 304 305 |
# File 'lib/active_support/callbacks.rb', line 297 def initialize(name, filter, kind, , chain_config) @chain_config = chain_config @name = name @kind = kind @filter = filter @key = compute_identifier filter @if = check_conditionals(Array([:if])) @unless = check_conditionals(Array([:unless])) end |
Instance Attribute Details
#chain_config ⇒ Object (readonly)
Returns the value of attribute chain_config.
295 296 297 |
# File 'lib/active_support/callbacks.rb', line 295 def chain_config @chain_config end |
#kind ⇒ Object
Returns the value of attribute kind.
294 295 296 |
# File 'lib/active_support/callbacks.rb', line 294 def kind @kind end |
#name ⇒ Object
Returns the value of attribute name.
294 295 296 |
# File 'lib/active_support/callbacks.rb', line 294 def name @name end |
Class Method Details
.build(chain, filter, kind, options) ⇒ Object
283 284 285 286 287 288 289 290 291 292 |
# File 'lib/active_support/callbacks.rb', line 283 def self.build(chain, filter, kind, ) if filter.is_a?(String) raise ArgumentError, <<-MSG.squish Passing string to define a callback is not supported. See the `.set_callback` documentation to see supported values. MSG end new chain.name, filter, kind, , chain.config end |
Instance Method Details
#apply(callback_sequence) ⇒ Object
Wraps code with filter
336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/active_support/callbacks.rb', line 336 def apply(callback_sequence) user_conditions = conditions_lambdas user_callback = CallTemplate.build(@filter, self) case kind when :before Filters::Before.build(callback_sequence, user_callback.make_lambda, user_conditions, chain_config, @filter) when :after Filters::After.build(callback_sequence, user_callback.make_lambda, user_conditions, chain_config) when :around callback_sequence.around(user_callback, user_conditions) end end |
#current_scopes ⇒ Object
350 351 352 |
# File 'lib/active_support/callbacks.rb', line 350 def current_scopes Array(chain_config[:scope]).map { |s| public_send(s) } end |
#duplicates?(other) ⇒ Boolean
326 327 328 329 330 331 332 333 |
# File 'lib/active_support/callbacks.rb', line 326 def duplicates?(other) case @filter when Symbol matches?(other.kind, other.filter) else false end end |
#filter ⇒ Object
307 |
# File 'lib/active_support/callbacks.rb', line 307 def filter; @key; end |
#matches?(_kind, _filter) ⇒ Boolean
322 323 324 |
# File 'lib/active_support/callbacks.rb', line 322 def matches?(_kind, _filter) @kind == _kind && filter == _filter end |
#merge_conditional_options(chain, if_option:, unless_option:) ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/active_support/callbacks.rb', line 310 def (chain, if_option:, unless_option:) = { if: @if.dup, unless: @unless.dup } [:if].concat Array(unless_option) [:unless].concat Array(if_option) self.class.build chain, @filter, @kind, end |
#raw_filter ⇒ Object
308 |
# File 'lib/active_support/callbacks.rb', line 308 def raw_filter; @filter; end |