Class: ActiveSupport::Callbacks::Callback
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activesupport/lib/active_support/callbacks.rb |
Overview
#
Constant Summary
-
EMPTY_ARRAY =
private
# File 'activesupport/lib/active_support/callbacks.rb', line 352[].freeze
Class Method Summary
Instance Attribute Summary
- #chain_config readonly
- #filter readonly
- #kind rw
- #name rw
Instance Method Summary
Constructor Details
.new(name, filter, kind, options, chain_config) ⇒ Callback
# File 'activesupport/lib/active_support/callbacks.rb', line 298
def initialize(name, filter, kind, , chain_config) @chain_config = chain_config @name = name @kind = kind @filter = filter @if = check_conditionals( [:if]) @unless = check_conditionals( [:unless]) end
Class Method Details
.build(chain, filter, kind, options)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 284
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 Attribute Details
#chain_config (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 296
attr_reader :chain_config, :filter
#filter (readonly)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 296
attr_reader :chain_config, :filter
#kind (rw)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 295
attr_accessor :kind, :name
#name (rw)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 295
attr_accessor :kind, :name
Instance Method Details
#apply(callback_sequence)
Wraps code with filter
# File 'activesupport/lib/active_support/callbacks.rb', line 333
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, name) 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
#check_conditionals(conditionals) (private)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 355
def check_conditionals(conditionals) return EMPTY_ARRAY if conditionals.blank? conditionals = Array(conditionals) if conditionals.any?(String) raise ArgumentError, <<-MSG.squish Passing string to be evaluated in :if and :unless conditional options is not supported. Pass a symbol for an instance method, or a lambda, proc or block, instead. MSG end conditionals.freeze end
#conditions_lambdas (private)
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 370
def conditions_lambdas @if.map { |c| CallTemplate.build(c, self).make_lambda } + @unless.map { |c| CallTemplate.build(c, self).inverted_lambda } end
#current_scopes
[ GitHub ]# File 'activesupport/lib/active_support/callbacks.rb', line 347
def current_scopes Array(chain_config[:scope]).map { |s| public_send(s) } end
#duplicates?(other) ⇒ Boolean
#matches?(_kind, _filter) ⇒ Boolean
# File 'activesupport/lib/active_support/callbacks.rb', line 319
def matches?(_kind, _filter) @kind == _kind && filter == _filter end