Class: Funfig::LoadProxy

Inherits:
BasicObject
Defined in:
lib/funfig/load_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(group) ⇒ LoadProxy

Returns a new instance of LoadProxy.



3
4
5
6
7
8
9
# File 'lib/funfig/load_proxy.rb', line 3

def initialize(group)
  @group = group
  methods = {}
  group.public_methods(false).each{|m| methods[m] = true}
  @methods = methods
  @params = @group.class._params
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/funfig/load_proxy.rb', line 20

def method_missing(name, *args, &block)
  if @methods.include?(name)
    if par = @params[name]
      if par.is_a?(::Class) && par < Group && args.empty? && block
        proxy = LoadProxy.new(@group.send(name))
        proxy.instance_exec &block
      elsif !args.empty?
        raise "Could not pass both block and value for option"  if block
        raise "Could set only single value for option"  if args.size > 1
        @group.send("#{name}=", args[0])
      else
        @group.send(name)
      end
    else
      @group.send(name, *args, &block)
    end
  else
    ::Kernel.raise ::NotImplementedError, "no configuration option #{@group._sub_name(name)}"
  end
end

Instance Method Details

#_parentObject



11
12
13
# File 'lib/funfig/load_proxy.rb', line 11

def _parent
  @group._parent
end

#_rootObject Also known as: _



15
16
17
# File 'lib/funfig/load_proxy.rb', line 15

def _root
  @group._root
end