class Commutator::Options::Proxy

Attributes

callback_name[R]
options[R]
proxied_history[R]

Public Class Methods

new(context, callback_name) click to toggle source
# File lib/commutator/options/proxy.rb, line 6
def initialize(context, callback_name)
  @context = context
  @callback_name = callback_name
  @proxied_history = []

  @options = instantiate_options
end

Public Instance Methods

context(context) click to toggle source
# File lib/commutator/options/proxy.rb, line 43
def context(context)
  @context = context
  @options = rehydrate_options
  self
end
count() click to toggle source
# File lib/commutator/options/proxy.rb, line 67
def count
  response = @context.client.send(callback_name, options.dup.select("COUNT"))
  response.inject(0) { |sum, page| sum + page.count }
end
execute() click to toggle source
# File lib/commutator/options/proxy.rb, line 53
def execute
  @context.send(callback_name, options)
end
first() click to toggle source
# File lib/commutator/options/proxy.rb, line 57
def first
  # TODO: asc / desc only work on Query (not Scan)
  limit(1).asc.execute.items.first
end
last() click to toggle source
# File lib/commutator/options/proxy.rb, line 62
def last
  # TODO: asc / desc only work on Query (not Scan)
  limit(1).desc.execute.items.first
end
method_missing(method_name, *args, &block) click to toggle source
Calls superclass method
# File lib/commutator/options/proxy.rb, line 31
def method_missing(method_name, *args, &block)
  super unless options.respond_to?(method_name)

  operation = Operation.new(method_name, args, block)
  result = operation.apply(@options, @proxied_history)
  result != options ? result : self
end
respond_to?(*args) click to toggle source
Calls superclass method
# File lib/commutator/options/proxy.rb, line 39
def respond_to?(*args)
  super || options.respond_to?(*args)
end

Private Instance Methods

instantiate_options() click to toggle source
# File lib/commutator/options/proxy.rb, line 74
def instantiate_options
  @context.run_before_hooks(
    @callback_name,
    @context.options_class(@callback_name).new._proxy(self)
  )
end
rehydrate_options() click to toggle source
# File lib/commutator/options/proxy.rb, line 81
def rehydrate_options
  instantiate_options.tap do |options|
    proxied_history.each { |operation| operation.apply(options) }
  end
end