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

- (CallbackChain) initialize(symbol)



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

def initialize(symbol)
  @symbol = symbol
end

Instance Method Details

- (Object) clone(klass)



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

- (Object) compile(key = nil, options = {})



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