Class: AsyncWrapper

Inherits:
ActiveSupport::ProxyObject
  • Object
show all
Defined in:
lib/cassandra-orm/async_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initialize(object, sync_method, &block) ⇒ AsyncWrapper

Returns a new instance of AsyncWrapper.



4
5
6
# File 'lib/cassandra-orm/async_wrapper.rb', line 4

def initialize object, sync_method, &block
  @object, @sync_method, @handler = object, sync_method, block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/cassandra-orm/async_wrapper.rb', line 8

def method_missing method, *args, &block
  if @object.respond_to? method
    @object.__send__ method, *args, &block
  else
    __getobj__.__send__ method, *args, &block
  end
end

Instance Method Details

#__getobj__Object



16
17
18
19
20
21
22
# File 'lib/cassandra-orm/async_wrapper.rb', line 16

def __getobj__
  @result ||= begin
    result = @object.__send__ @sync_method
    result = @handler.call result if @handler
    result
  end
end