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
146 147 148 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 146 def delete(callback) super(callback.is_a?(Callback) ? callback : find(callback)) end |
#find(callback, &block) ⇒ Object
142 143 144 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 142 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
133 134 135 136 137 138 139 140 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 133 def replace_or_append!(chain) if index = index(chain) self[index] = chain else self << chain end self end |
#run(object, options = {}, &terminator) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/mongo_mapper/plugins/callbacks.rb', line 121 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 |