Class: ActiveSupport::Callbacks::CallbackChain
- Defined in:
- lib/active_support/callbacks.rb
Overview
An Array with a compile method
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #compile(key = nil, object = nil) ⇒ Object
-
#initialize(name, config) ⇒ CallbackChain
constructor
A new instance of CallbackChain.
Methods inherited from Array
#as_json, #encode_json, #extract_options!, #fifth, #forty_two, #fourth, #from, #in_groups, #in_groups_of, #sample, #second, #split, #third, #to, #to_formatted_s, #to_param, #to_query, #to_sentence, #to_xml, #uniq_by, #uniq_by!, wrap
Constructor Details
#initialize(name, config) ⇒ CallbackChain
Returns a new instance of CallbackChain.
342 343 344 345 346 347 348 349 |
# File 'lib/active_support/callbacks.rb', line 342 def initialize(name, config) @name = name @config = { :terminator => "false", :rescuable => false, :scope => [ :kind ] }.merge(config) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
340 341 342 |
# File 'lib/active_support/callbacks.rb', line 340 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
340 341 342 |
# File 'lib/active_support/callbacks.rb', line 340 def name @name end |
Instance Method Details
#compile(key = nil, object = nil) ⇒ Object
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
# File 'lib/active_support/callbacks.rb', line 351 def compile(key=nil, object=nil) method = [] method << "value = nil" method << "halted = false" each do |callback| method << callback.start(key, object) end if config[:rescuable] method << "rescued_error = nil" method << "begin" end method << "value = yield if block_given? && !halted" if config[:rescuable] method << "rescue Exception => e" method << "rescued_error = e" method << "end" end reverse_each do |callback| method << callback.end(key, object) end method << "raise rescued_error if rescued_error" if config[:rescuable] method << "halted ? false : (block_given? ? value : true)" method.compact.join("\n") end |