Class: CassandraModel::Callbacks::CallbackChain

Inherits:
Array
  • Object
show all
Defined in:
lib/cassandra-model/callbacks.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build(kind, *methods, &block) ⇒ Object



80
81
82
83
84
# File 'lib/cassandra-model/callbacks.rb', line 80

def self.build(kind, *methods, &block)
  methods, options = extract_options(*methods, &block)
  methods.map! { |method| Callback.new(kind, method, options) }
  new(methods)
end

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, options = {}, &terminator)
  enumerator = options[: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