Class: Wonkavision::Plugins::Callbacks::CallbackChain
- Inherits:
-
Array
- Object
- Array
- Wonkavision::Plugins::Callbacks::CallbackChain
- Defined in:
- lib/wonkavision/plugins/callbacks.rb
Class Method Summary collapse
Instance Method Summary collapse
- #delete(callback) ⇒ Object
- #find(callback, &block) ⇒ Object
- #replace_or_append!(chain) ⇒ Object
- #run(object, options = {}, &terminator) ⇒ Object
Class Method Details
Instance Method Details
#delete(callback) ⇒ Object
94 95 96 |
# File 'lib/wonkavision/plugins/callbacks.rb', line 94 def delete(callback) super(callback.is_a?(Callback) ? callback : find(callback)) end |
#find(callback, &block) ⇒ Object
90 91 92 |
# File 'lib/wonkavision/plugins/callbacks.rb', line 90 def find(callback, &block) select { |c| c == callback && (!block_given? || yield(c)) }.first end |
#replace_or_append!(chain) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/wonkavision/plugins/callbacks.rb', line 81 def replace_or_append!(chain) if index = index(chain) self[index] = chain else self << chain end self end |
#run(object, options = {}, &terminator) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/wonkavision/plugins/callbacks.rb', line 68 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 |