Module: ActiveLayer::Proxy::InstanceMethods

Defined in:
lib/active_layer/proxy.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



22
23
24
25
26
27
28
29
# File 'lib/active_layer/proxy.rb', line 22

def method_missing(method, *args, &block)
  # puts "passing: #{method} + #{args.inspect} to #{active_layer_object.inspect}"
  unless @active_layer_object.nil?
    active_layer_object.send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#active_layer_objectObject



17
18
19
20
# File 'lib/active_layer/proxy.rb', line 17

def active_layer_object
  raise "active_layer_object was not set" if @active_layer_object.nil?
  @active_layer_object
end

#initialize(*args, &block) ⇒ Object



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

def initialize(*args, &block)
  self.active_layer_object = args.first
  super()
end

#read_attribute_for_validation(key) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/active_layer/proxy.rb', line 31

def read_attribute_for_validation(key)
  if active_layer_object.respond_to?(:read_attribute_for_validation)
    active_layer_object.read_attribute_for_validation(key)
  else
    active_layer_object.send(key)
  end
end

#respond_to?(method, use_proxy = true) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/active_layer/proxy.rb', line 39

def respond_to?(method, use_proxy = true)
  super(method) || ( use_proxy && @active_layer_object && @active_layer_object.respond_to?(method) )
end