Sha256: 249aea05fdfeab42351051487e99f1c510c26fc8e46e58c8a847853a09cd1854

Contents?: true

Size: 746 Bytes

Versions: 17

Compression:

Stored size: 746 Bytes

Contents

module RubyPitaya

  class SetupSpecHelper

    def initialize
      @setup_mock = {}
    end

    def [](key)
      split_key = key.split('.')
      @setup_mock.dig(*split_key)
    end

    def auto_reload
    end

    def setup_mock=(value)
      @setup_mock = value
    end

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

    def fetch(*args)
      @setup_mock.fetch(*args)
    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

17 entries across 17 versions & 1 rubygems

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