Class: ComplexConfig::Proxy

Inherits:
BasicObject
Defined in:
lib/complex_config/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(env = nil) ⇒ Proxy

Returns a new instance of Proxy.



3
4
5
# File 'lib/complex_config/proxy.rb', line 3

def initialize(env = nil)
  @env = env
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/complex_config/proxy.rb', line 20

def method_missing(name, *args)
  if name =~ /\?\z/
    method_name, name = name, $`
    exist = ::ComplexConfig::Provider.exist?(name)
    (class << self; self; end).class_eval do
      define_method(method_name) do |env = nil|
        if exist
          __send__(name, *args)
        else
          nil
        end
      end
    end
    __send__(method_name, *args)
  else
    config = ::ComplexConfig::Provider[name]
    (class << self; self; end).class_eval do
      define_method(name) do |env = nil|
        if env
          config[env]
        elsif @env
          config[@env]
        else
          config
        end
      end
    end
    __send__(name, *args)
  end
end

Instance Method Details

#inspect ⇒ Object



11
12
13
# File 'lib/complex_config/proxy.rb', line 11

def inspect
  "#<#{to_s}>"
end

#reload ⇒ Object



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

def reload
  ::ComplexConfig::Provider.flush_cache
  self
end

#to_s ⇒ Object



7
8
9
# File 'lib/complex_config/proxy.rb', line 7

def to_s
  'ComplexConfig::Proxy'
end