Class: MongoMapper::Plugins::Callbacks::CallbackChain
- Defined in:
- lib/mongo_mapper/plugins/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
Class Method Details
Instance Method Details
#delete(callback) ⇒ Object
153 154 155 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 153 def delete(callback) super(callback.is_a?(Callback) ? callback : find(callback)) end |
#find(callback, &block) ⇒ Object
149 150 151 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 149 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
140 141 142 143 144 145 146 147 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 140 def replace_or_append!(chain) if index = index(chain) self[index] = chain else self << chain end self end |
#run(object, options = {}, &terminator) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 126 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 |