Sha256: 2e96b073d0552a2648e6de64af2747d2b2d224476c7be694207b0f5015201286

Contents?: true

Size: 1.05 KB

Versions: 22

Compression:

Stored size: 1.05 KB

Contents

module RubyPitaya

  class ConfigSpecHelper

    def initialize(default_config = {})
      @config_mock = {}
      @default_config = default_config
    end

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

      return @default_config[key]
    end

    def auto_reload
    end

    def config_mock=(value)
      @config_mock = value.deep_symbolize_keys.stringify_keys
    end

    def config_core_override=(value)
    end

    def add(key, value)
      keys = key.split('.')
      add_hash = undig(*keys, value)
      @config_mock = merge_recursively(@config_mock, add_hash).deep_symbolize_keys.stringify_keys
    end

    def clear
      @config_mock = {}
    end

    private

    def undig(*keys, value)
      keys.empty? ? value : { keys.first=>undig(*keys.drop(1), value) }
    end

    def merge_recursively(a, b)
      a.merge(b) do |key, a_item, b_item|
        if a_item.is_a?(Hash) && b_item.is_a?(Hash)
          merge_recursively(a_item, b_item)
        else
          a[key] = b_item
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rubypitaya-3.19.6 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.19.5 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.19.4 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.19.3 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.19.2 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.19.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.19.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.18.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.17.2 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.17.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.17.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.16.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.15.3 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.15.2 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.15.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.15.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.14.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.13.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.13.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.12.5 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb