Module: Beanstalker::Extensions

Defined in:
lib/beanstalker/queue.rb,
lib/beanstalker/extend.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(receiver) ⇒ Object



32
33
34
35
# File 'lib/beanstalker/extend.rb', line 32

def self.included(receiver)
  @@methods_async_options = {}
  receiver.extend(ClassMethods)
end

Instance Method Details

#async_send(selector, *args) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/beanstalker/extend.rb', line 73

def async_send(selector, *args)
  if self.is_a?(Class)
    methods_async_options = self.send(:instance_variable_get, :@class_methods_async_options) || {}
  else
    methods_async_options = self.class.send(:instance_variable_get, :@methods_async_options) || {}
  end
  async_send_opts(selector, methods_async_options[selector.to_sym] || {}, *args)
end

#async_send_opts(selector, opts, *args) ⇒ Object



82
83
84
85
# File 'lib/beanstalker/extend.rb', line 82

def async_send_opts(selector, opts, *args)
  interpolated_options = interpolate_async_options(opts, self, *args)
  Beanstalker::Queue.put_call!(self, selector, interpolated_options, args)
end

#interpolate_async_options(options, object, *args) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/beanstalker/extend.rb', line 61

def interpolate_async_options(options, object, *args)
  result = {}
  options.each do |k,v|
    result[k] = if v.is_a?(Proc)
      v.call(object, *args)
    else
      v
    end
  end
  result
end

#rreprObject



190
191
192
193
# File 'lib/beanstalker/queue.rb', line 190

def rrepr()
  method = (respond_to? :get_cache) ? 'get_cache' : 'find'
  "#{self.class.rrepr}.#{method}(#{id.rrepr})"
end