Class: CouchRest::Callbacks::CallbackChain

Inherits:
Array
  • Object
show all
Defined in:
lib/couchrest/mixins/callbacks.rb

Overview

An Array with a compile method

Instance Method Summary collapse

Constructor Details

#initialize(symbol) ⇒ CallbackChain

Returns a new instance of CallbackChain.



321
322
323
# File 'lib/couchrest/mixins/callbacks.rb', line 321

def initialize(symbol)
  @symbol = symbol
end

Instance Method Details

#clone(klass) ⇒ Object



338
339
340
341
# File 'lib/couchrest/mixins/callbacks.rb', line 338

def clone(klass)
  chain = CallbackChain.new(@symbol)
  chain.push(*map {|c| c.clone(klass)})
end

#compile(key = nil, options = {}) ⇒ Object



325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/couchrest/mixins/callbacks.rb', line 325

def compile(key = nil, options = {})
  method = []
  method << "halted = false"
  each do |callback|
    method << callback.start(key, options)
  end
  method << "yield self if block_given?"
  reverse_each do |callback|
    method << callback.end(key, options)
  end
  method.compact.join("\n")
end