Class: ActiveSupport::Callbacks::CallbackChain
- Defined in:
- lib/gems/activesupport-2.2.2/lib/active_support/callbacks.rb
Class Method Summary collapse
Instance Method Summary collapse
- #delete(callback) ⇒ Object
- #find(callback, &block) ⇒ Object
-
#replace_or_append!(chain) ⇒ Object
TODO: Decompose into more Array like behavior.
- #run(object, options = {}, &terminator) ⇒ Object
Methods inherited from Array
#count, #include?, #invert, #parse_splat_args, #random_each, #randomize, #randomize!, #subset?, #superset?
Methods included from ActiveSupport::CoreExtensions::Array::RandomAccess
Methods included from ActiveSupport::CoreExtensions::Array::Grouping
#in_groups, #in_groups_of, #split
Methods included from ActiveSupport::CoreExtensions::Array::ExtractOptions
Methods included from ActiveSupport::CoreExtensions::Array::Conversions
included, #to_formatted_s, #to_param, #to_query, #to_sentence, #to_xml
Methods included from ActiveSupport::CoreExtensions::Array::Access
#fifth, #forty_two, #fourth, #from, #second, #third, #to
Methods included from English::Array
Class Method Details
.build(kind, *methods, &block) ⇒ Object
80 81 82 83 84 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/callbacks.rb', line 80 def self.build(kind, *methods, &block) methods, = (*methods, &block) methods.map! { |method| Callback.new(kind, method, ) } new(methods) end |
Instance Method Details
#delete(callback) ⇒ Object
113 114 115 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/callbacks.rb', line 113 def delete(callback) super(callback.is_a?(Callback) ? callback : find(callback)) end |
#find(callback, &block) ⇒ Object
109 110 111 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/callbacks.rb', line 109 def find(callback, &block) select { |c| c == callback && (!block_given? || yield(c)) }.first end |
#replace_or_append!(chain) ⇒ Object
TODO: Decompose into more Array like behavior
100 101 102 103 104 105 106 107 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/callbacks.rb', line 100 def replace_or_append!(chain) if index = index(chain) self[index] = chain else self << chain end self end |
#run(object, options = {}, &terminator) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gems/activesupport-2.2.2/lib/active_support/callbacks.rb', line 86 def run(object, = {}, &terminator) enumerator = [:enumerator] || :each unless block_given? send(enumerator) { |callback| callback.call(object) } else send(enumerator) do |callback| result = callback.call(object) break result if terminator.call(result, object) end end end |