Module: Raiblocks::Proxy::ClassMethods

Defined in:
lib/raiblocks/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &_block) ⇒ Object (private)



52
53
54
55
56
# File 'lib/raiblocks/proxy.rb', line 52

def method_missing(m, *args, &_block)
  return super unless valid_method?(m)
  define_proxy_method(m, true)
  send(m, args.first)
end

Instance Attribute Details

#proxy_method_defObject (readonly)

Returns the value of attribute proxy_method_def.



13
14
15
# File 'lib/raiblocks/proxy.rb', line 13

def proxy_method_def
  @proxy_method_def
end

#proxy_param_defObject (readonly)

Returns the value of attribute proxy_param_def.



13
14
15
# File 'lib/raiblocks/proxy.rb', line 13

def proxy_param_def
  @proxy_param_def
end

Instance Method Details

#define_proxy_method(m, singleton = false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/raiblocks/proxy.rb', line 32

def define_proxy_method(m, singleton = false)
  send(
    singleton ? :define_singleton_method : :define_method,
    method_alias(m)
  ) do |opts = {}|
    params = Raiblocks::ProxyContext.new(
      singleton ? self : self.class, m, opts
    ).populate_params(singleton ? nil : base_params)
    data = Raiblocks.client.call(m, params)
    data.is_a?(Hash) && data.keys.map(&:to_s) == [m.to_s] ? data[m] : data
  end
end

#methodsObject



28
29
30
# File 'lib/raiblocks/proxy.rb', line 28

def methods
  (super + proxy_methods).sort
end

#proxy_method(name, signature = nil) ⇒ Object



19
20
21
22
# File 'lib/raiblocks/proxy.rb', line 19

def proxy_method(name, signature = nil)
  @proxy_method_def ||= {}
  @proxy_method_def[name] = signature
end

#proxy_methodsObject



24
25
26
# File 'lib/raiblocks/proxy.rb', line 24

def proxy_methods
  proxy_method_def.keys.sort
end

#proxy_params(param_def = nil) ⇒ Object



15
16
17
# File 'lib/raiblocks/proxy.rb', line 15

def proxy_params(param_def = nil)
  @proxy_param_def = param_def
end