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.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#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.
- #compiled ⇒ Object
- #current_scopes ⇒ Object
- #duplicates?(other) ⇒ Boolean
-
#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
Constructor Details
#initialize(name, filter, kind, options, chain_config) ⇒ Callback
Returns a new instance of Callback.
246 247 248 249 250 251 252 253 254 255 |
# File 'lib/active_support/callbacks.rb', line 246 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]) compiled end |
Instance Attribute Details
#chain_config ⇒ Object (readonly)
Returns the value of attribute chain_config.
244 245 246 |
# File 'lib/active_support/callbacks.rb', line 244 def chain_config @chain_config end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
244 245 246 |
# File 'lib/active_support/callbacks.rb', line 244 def filter @filter end |
#kind ⇒ Object
Returns the value of attribute kind.
243 244 245 |
# File 'lib/active_support/callbacks.rb', line 243 def kind @kind end |
#name ⇒ Object
Returns the value of attribute name.
243 244 245 |
# File 'lib/active_support/callbacks.rb', line 243 def name @name end |
Class Method Details
.build(chain, filter, kind, options) ⇒ Object
232 233 234 235 236 237 238 239 240 241 |
# File 'lib/active_support/callbacks.rb', line 232 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
300 301 302 |
# File 'lib/active_support/callbacks.rb', line 300 def apply(callback_sequence) compiled.apply(callback_sequence) end |
#compiled ⇒ Object
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/active_support/callbacks.rb', line 282 def compiled @compiled ||= begin user_conditions = conditions_lambdas user_callback = CallTemplate.build(@filter, self) case kind when :before Filters::Before.new(user_callback.make_lambda, user_conditions, chain_config, @filter, name) when :after Filters::After.new(user_callback.make_lambda, user_conditions, chain_config) when :around Filters::Around.new(user_callback, user_conditions) end end end |
#current_scopes ⇒ Object
304 305 306 |
# File 'lib/active_support/callbacks.rb', line 304 def current_scopes Array(chain_config[:scope]).map { |s| public_send(s) } end |
#duplicates?(other) ⇒ Boolean
273 274 275 276 277 278 279 280 |
# File 'lib/active_support/callbacks.rb', line 273 def duplicates?(other) case @filter when Symbol matches?(other.kind, other.filter) else false end end |
#matches?(_kind, _filter) ⇒ Boolean
269 270 271 |
# File 'lib/active_support/callbacks.rb', line 269 def matches?(_kind, _filter) @kind == _kind && filter == _filter end |
#merge_conditional_options(chain, if_option:, unless_option:) ⇒ Object
257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/active_support/callbacks.rb', line 257 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 |