Sha256: 21b43975a2cb7be4286e2b5bacb7a04885e7ab2c8c513015bdb5af4e2b2a9382

Contents?: true

Size: 808 Bytes

Versions: 34

Compression:

Stored size: 808 Bytes

Contents

module RubyPitaya

  class ConfigSpecHelper

    def initialize
      @config_mock = {}
    end

    def [](key)
      split_key = key.split('.')
      @config_mock.dig(*split_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

    private

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

    def merge_recursively(a, b)
      a.merge(b) {|key, a_item, b_item| merge_recursively(a_item, b_item) }
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
rubypitaya-3.5.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.4.2 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.4.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.4.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.3.7 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.3.6 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.3.5 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.3.4 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.3.3 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.3.2 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.3.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.3.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.2.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.1.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.1.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.0.3 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.0.2 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.0.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.0.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-2.27.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb