Sha256: a3f7fc4f9f4db769465662dbdeb5452248401dccfe72c591a601e10c6271714b

Contents?: true

Size: 1.02 KB

Versions: 51

Compression:

Stored size: 1.02 KB

Contents

require 'rubypitaya/core/config_core'

module RubyPitaya

  class Config

    def initialize
      @config_core = ConfigCore.new
      @config_core_override = nil
      @has_config_core_override = false

      @empty_hash = {}
      @result_cache = {}
    end

    def [](key)
      result = @result_cache[key]
      return result unless result.nil?

      if @has_config_core_override
        result = @config_core_override[key]
        result = @config_core[key] if result.nil?
      else
        result = @config_core[key]
      end

      @result_cache[key] = result

      result
    end

    def fetch(*args)
      result = self[args[0]]
      return result unless result.nil?

      @empty_hash.fetch(*args)
    end

    def auto_reload
      @config_core.auto_reload
      @config_core_override.auto_reload unless @config_core_override.nil?
    end

    def clear_cache
      @result_cache.clear
    end

    def config_core_override=(value)
      @config_core_override = value
      @has_config_core_override = !value.nil?
    end
  end
end

Version data entries

51 entries across 47 versions & 1 rubygems

Version Path
rubypitaya-2.27.0 ./lib/rubypitaya/core/config.rb
rubypitaya-2.26.3 ./lib/rubypitaya/core/config.rb
rubypitaya-2.26.2 ./lib/rubypitaya/core/config.rb
rubypitaya-2.26.1 ./lib/rubypitaya/core/config.rb
rubypitaya-2.26.0 ./lib/rubypitaya/core/config.rb
rubypitaya-2.25.1 ./lib/rubypitaya/core/config.rb
rubypitaya-2.25.0 ./lib/rubypitaya/core/config.rb
rubypitaya-2.24.0 ./lib/rubypitaya/core/config.rb
rubypitaya-2.23.0 ./lib/rubypitaya/core/config.rb
rubypitaya-2.22.0 ./lib/rubypitaya/core/config.rb
rubypitaya-2.21.0 ./lib/rubypitaya/core/config.rb