Module: AsyncObserver::Extensions

Defined in:
lib/async_observer/queue.rb,
lib/async_observer/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/async_observer/extend.rb', line 32

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

Instance Method Details

#async_send(selector, *args) ⇒ Object



58
59
60
# File 'lib/async_observer/extend.rb', line 58

def async_send(selector, *args)
  async_send_opts(selector, @@methods_async_options[selector.to_sym] || {}, *args)
end

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



62
63
64
65
# File 'lib/async_observer/extend.rb', line 62

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

#interpolate_async_options(options, object) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/async_observer/extend.rb', line 46

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

#rreprObject



185
186
187
188
# File 'lib/async_observer/queue.rb', line 185

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