Class: CouchRest::Mixins::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.



349
350
351
# File 'lib/couchrest/mixins/callbacks.rb', line 349

def initialize(symbol)
  @symbol = symbol
end

Instance Method Details

#clone(klass) ⇒ Object



366
367
368
369
# File 'lib/couchrest/mixins/callbacks.rb', line 366

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

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



353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/couchrest/mixins/callbacks.rb', line 353

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