Sha256: ab1daacda3658d1f2f62ba8ab991a722c341fb62fe1808baf046b11adf7fc064

Contents?: true

Size: 978 Bytes

Versions: 14

Compression:

Stored size: 978 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

    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

14 entries across 13 versions & 1 rubygems

Version Path
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rubypitaya-3.12.1/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rubypitaya-3.12.1/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rubypitaya-3.12.1/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/rubypitaya-3.12.1/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.12.2 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.12.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.12.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.11.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.10.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.9.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.8.1 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.8.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.7.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb
rubypitaya-3.6.0 ./lib/rubypitaya/core/spec-helpers/config_spec_helper.rb