Class: RailsAdmin::Config::Proxyable::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_admin/config/proxyable/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, bindings = {}) ⇒ Proxy

Returns a new instance of Proxy.



11
12
13
14
# File 'lib/rails_admin/config/proxyable/proxy.rb', line 11

def initialize(object, bindings = {})
  @object = object
  @bindings = bindings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rails_admin/config/proxyable/proxy.rb', line 26

def method_missing(name, *args, &block)
  if @object.respond_to?(name)
    reset = @object.instance_variable_get("@bindings")
    begin
      @object.instance_variable_set("@bindings", @bindings)
      response = @object.__send__(name, *args, &block)
    ensure
      @object.instance_variable_set("@bindings", @reset)
    end
    response
  else
    super(name, *args, &block)
  end
end

Instance Attribute Details

#bindingsObject (readonly)

Returns the value of attribute bindings.



9
10
11
# File 'lib/rails_admin/config/proxyable/proxy.rb', line 9

def bindings
  @bindings
end

Instance Method Details

#bind(key, value = nil) ⇒ Object

Bind variables to be used by the configuration options



17
18
19
20
21
22
23
24
# File 'lib/rails_admin/config/proxyable/proxy.rb', line 17

def bind(key, value = nil)
  if key.kind_of?(Hash)
    @bindings = key
  else
    @bindings[key] = value
  end
  self
end