Class: CassandraModel::Callbacks::CallbackChain
- Defined in:
- lib/cassandra-model/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
Class Method Details
Instance Method Details
#delete(callback) ⇒ Object
113 114 115 |
# File 'lib/cassandra-model/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/cassandra-model/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/cassandra-model/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/cassandra-model/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 |