Sha256: 76fcfc121356e2e8999eb6b6da7afa92cdb192dc77b4c0d5711daf497e917544

Contents?: true

Size: 1.06 KB

Versions: 24

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 ||= @env
              config[env] || ::ComplexConfig::Settings.new
            else
              config
            end
          end
        end
        __send__(name, *args)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
complex_config-0.22.2 lib/complex_config/proxy.rb
complex_config-0.22.1 lib/complex_config/proxy.rb
complex_config-0.22.0 lib/complex_config/proxy.rb
complex_config-0.21.2 lib/complex_config/proxy.rb
complex_config-0.21.1 lib/complex_config/proxy.rb
complex_config-0.21.0 lib/complex_config/proxy.rb
complex_config-0.20.0 lib/complex_config/proxy.rb
complex_config-0.19.4 lib/complex_config/proxy.rb
complex_config-0.19.3 lib/complex_config/proxy.rb
complex_config-0.19.2 lib/complex_config/proxy.rb
complex_config-0.19.1 lib/complex_config/proxy.rb
complex_config-0.19.0 lib/complex_config/proxy.rb
complex_config-0.18.2 lib/complex_config/proxy.rb
complex_config-0.18.1 lib/complex_config/proxy.rb
complex_config-0.18.0 lib/complex_config/proxy.rb
complex_config-0.17.1 lib/complex_config/proxy.rb
complex_config-0.17.0 lib/complex_config/proxy.rb
complex_config-0.16.0 lib/complex_config/proxy.rb
complex_config-0.15.1 lib/complex_config/proxy.rb
complex_config-0.15.0 lib/complex_config/proxy.rb