Class: ActiveSupport::Callbacks::CallbackChain
- Includes:
- Enumerable
- Defined in:
- activesupport/lib/active_support/callbacks.rb
Overview
:nodoc:
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
- #append(*callbacks) ⇒ Object
- #clear ⇒ Object
- #compile(type) ⇒ Object
- #delete(o) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #index(o) ⇒ Object
-
#initialize(name, config) ⇒ CallbackChain
constructor
A new instance of CallbackChain.
- #initialize_copy(other) ⇒ Object
- #insert(index, o) ⇒ Object
- #prepend(*callbacks) ⇒ Object
Methods included from Enumerable
Constructor Details
#initialize(name, config) ⇒ CallbackChain
Returns a new instance of CallbackChain.
609 610 611 612 613 614 615 616 617 618 619 |
# File 'activesupport/lib/active_support/callbacks.rb', line 609 def initialize(name, config) @name = name @config = { scope: [:kind], terminator: default_terminator }.merge!(config) @chain = [] @all_callbacks = nil @single_callbacks = {} @mutex = Mutex.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config
607 608 609 |
# File 'activesupport/lib/active_support/callbacks.rb', line 607 def config @config end |
#name ⇒ Object (readonly)
Returns the value of attribute name
607 608 609 |
# File 'activesupport/lib/active_support/callbacks.rb', line 607 def name @name end |
Instance Method Details
#append(*callbacks) ⇒ Object
669 670 671 |
# File 'activesupport/lib/active_support/callbacks.rb', line 669 def append(*callbacks) callbacks.each { |c| append_one(c) } end |
#clear ⇒ Object
637 638 639 640 641 642 |
# File 'activesupport/lib/active_support/callbacks.rb', line 637 def clear @all_callbacks = nil @single_callbacks.clear @chain.clear self end |
#compile(type) ⇒ Object
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 |
# File 'activesupport/lib/active_support/callbacks.rb', line 651 def compile(type) if type.nil? @all_callbacks || @mutex.synchronize do final_sequence = CallbackSequence.new @all_callbacks ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback| callback.apply(callback_sequence) end end else @single_callbacks[type] || @mutex.synchronize do final_sequence = CallbackSequence.new @single_callbacks[type] ||= @chain.reverse.inject(final_sequence) do |callback_sequence, callback| type == callback.kind ? callback.apply(callback_sequence) : callback_sequence end end end end |
#delete(o) ⇒ Object
631 632 633 634 635 |
# File 'activesupport/lib/active_support/callbacks.rb', line 631 def delete(o) @all_callbacks = nil @single_callbacks.clear @chain.delete(o) end |
#each(&block) ⇒ Object
621 |
# File 'activesupport/lib/active_support/callbacks.rb', line 621 def each(&block); @chain.each(&block); end |
#empty? ⇒ Boolean
623 |
# File 'activesupport/lib/active_support/callbacks.rb', line 623 def empty?; @chain.empty?; end |
#index(o) ⇒ Object
622 |
# File 'activesupport/lib/active_support/callbacks.rb', line 622 def index(o); @chain.index(o); end |
#initialize_copy(other) ⇒ Object
644 645 646 647 648 649 |
# File 'activesupport/lib/active_support/callbacks.rb', line 644 def initialize_copy(other) @all_callbacks = nil @single_callbacks = {} @chain = other.chain.dup @mutex = Mutex.new end |
#insert(index, o) ⇒ Object
625 626 627 628 629 |
# File 'activesupport/lib/active_support/callbacks.rb', line 625 def insert(index, o) @all_callbacks = nil @single_callbacks.clear @chain.insert(index, o) end |
#prepend(*callbacks) ⇒ Object
673 674 675 |
# File 'activesupport/lib/active_support/callbacks.rb', line 673 def prepend(*callbacks) callbacks.each { |c| prepend_one(c) } end |