Sha256: d4685f32c909bd39e12b403af2a24836351978f157e9af831e436fbf0874f031

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

module ComplexConfig
  class Proxy < BasicObject
    def initialize(env = nil)
      @env = env
    end

    def to_s
      'ComplexConfig::Proxy'
    end

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

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

    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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
complex_config-0.13.1 lib/complex_config/proxy.rb
complex_config-0.13.0 lib/complex_config/proxy.rb
complex_config-0.12.1 lib/complex_config/proxy.rb
complex_config-0.12.0 lib/complex_config/proxy.rb
complex_config-0.11.3 lib/complex_config/proxy.rb
complex_config-0.11.2 lib/complex_config/proxy.rb
complex_config-0.11.1 lib/complex_config/proxy.rb
complex_config-0.11.0 lib/complex_config/proxy.rb
complex_config-0.10.0 lib/complex_config/proxy.rb