Class: RailsAdminNext::Config::Proxyable::Proxy

Inherits:
BasicObject
Defined in:
lib/rails_admin_next/config/proxyable/proxy.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Proxy.



7
8
9
10
# File 'lib/rails_admin_next/config/proxyable/proxy.rb', line 7

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name) ⇒ Object

Transparent proxy: Proxy < BasicObject has no respond_to?, so respond_to_missing? would be dead code (nothing ever calls it) — a bare proxy.respond_to?(:x) is itself delegated through method_missing.



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

def method_missing(method_name, *, &) # standard:disable Style/MissingRespondToMissing
  if @object.respond_to?(method_name)
    reset = @object.bindings
    begin
      @object.bindings = @bindings
      response = @object.__send__(method_name, *, &)
    ensure
      @object.bindings = reset
    end
    response
  else
    super
  end
end

Instance Method Details

#bind(key, value = nil) ⇒ Object

Bind variables to be used by the configuration options



13
14
15
16
17
18
19
20
# File 'lib/rails_admin_next/config/proxyable/proxy.rb', line 13

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