Class: SqlcachedClient::ProxyObject

Inherits:
BasicObject
Defined in:
lib/sqlcached_client/proxy_object.rb

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ ProxyObject

Returns a new instance of ProxyObject.



4
5
6
# File 'lib/sqlcached_client/proxy_object.rb', line 4

def initialize(context)
  @context = context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object



8
9
10
# File 'lib/sqlcached_client/proxy_object.rb', line 8

def method_missing(symbol, *args)
  @context.send(symbol, *args)
end

Instance Method Details

#execute(*args, &block) ⇒ Object



12
13
14
# File 'lib/sqlcached_client/proxy_object.rb', line 12

def execute(*args, &block)
  instance_exec(*args, &block)
end

#plug_method(method_name, &method_body) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sqlcached_client/proxy_object.rb', line 16

def plug_method(method_name, &method_body)
  memoize_var = "@m_#{method_name}"
  instance_variable_set(memoize_var, method_body)
  eval(
    "      def self.\#{method_name}(*args, &block)\n        instance_exec(*args, block, &\#{memoize_var})\n      end\n    RUBY\n  )\n  method_name.to_sym\nend\n"