Class: CouchRest::Callbacks::CallbackChain

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

Overview

An Array with a compile method

Instance Method Summary collapse

Methods inherited from Array

#extract_options!, wrap

Constructor Details

#initialize(symbol) ⇒ CallbackChain

Returns a new instance of CallbackChain.



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

def initialize(symbol)
  @symbol = symbol
end

Instance Method Details

#clone(klass) ⇒ Object



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

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

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



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

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