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.
- #duplicates?(other) ⇒ Boolean
- #filter ⇒ Object
-
#initialize(name, filter, kind, options, chain_config) ⇒ Callback
constructor
A new instance of Callback.
- #matches?(_kind, _filter) ⇒ Boolean
- #merge(chain, new_options) ⇒ Object
- #raw_filter ⇒ Object
Constructor Details
#initialize(name, filter, kind, options, chain_config) ⇒ Callback
Returns a new instance of Callback.
361 362 363 364 365 366 367 368 369 |
# File 'lib/active_support/callbacks.rb', line 361 def initialize(name, filter, kind, , chain_config) @chain_config = chain_config @name = name @kind = kind @filter = filter @key = compute_identifier filter @if = Array([:if]) @unless = Array([:unless]) end |
Instance Attribute Details
#chain_config ⇒ Object (readonly)
Returns the value of attribute chain_config.
359 360 361 |
# File 'lib/active_support/callbacks.rb', line 359 def chain_config @chain_config end |
#kind ⇒ Object
Returns the value of attribute kind.
358 359 360 |
# File 'lib/active_support/callbacks.rb', line 358 def kind @kind end |
#name ⇒ Object
Returns the value of attribute name.
358 359 360 |
# File 'lib/active_support/callbacks.rb', line 358 def name @name end |
Class Method Details
.build(chain, filter, kind, options) ⇒ Object
354 355 356 |
# File 'lib/active_support/callbacks.rb', line 354 def self.build(chain, filter, kind, ) new chain.name, filter, kind, , chain.config end |
Instance Method Details
#apply(callback_sequence) ⇒ Object
Wraps code with filter
400 401 402 403 404 405 406 407 408 409 410 411 412 |
# File 'lib/active_support/callbacks.rb', line 400 def apply(callback_sequence) user_conditions = conditions_lambdas user_callback = make_lambda @filter case kind when :before Filters::Before.build(callback_sequence, user_callback, user_conditions, chain_config, @filter) when :after Filters::After.build(callback_sequence, user_callback, user_conditions, chain_config) when :around Filters::Around.build(callback_sequence, user_callback, user_conditions, chain_config) end end |
#duplicates?(other) ⇒ Boolean
390 391 392 393 394 395 396 397 |
# File 'lib/active_support/callbacks.rb', line 390 def duplicates?(other) case @filter when Symbol, String matches?(other.kind, other.filter) else false end end |
#filter ⇒ Object
371 |
# File 'lib/active_support/callbacks.rb', line 371 def filter; @key; end |
#matches?(_kind, _filter) ⇒ Boolean
386 387 388 |
# File 'lib/active_support/callbacks.rb', line 386 def matches?(_kind, _filter) @kind == _kind && filter == _filter end |
#merge(chain, new_options) ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 |
# File 'lib/active_support/callbacks.rb', line 374 def merge(chain, ) = { :if => @if.dup, :unless => @unless.dup } [:if].concat Array(.fetch(:unless, [])) [:unless].concat Array(.fetch(:if, [])) self.class.build chain, @filter, @kind, end |
#raw_filter ⇒ Object
372 |
# File 'lib/active_support/callbacks.rb', line 372 def raw_filter; @filter; end |