Sha256: 331353d3a9a215f96f8cb93ece751b65b64ca793a3752aae41a3b0479b55cd56
Contents?: true
Size: 879 Bytes
Versions: 5
Compression:
Stored size: 879 Bytes
Contents
# frozen_string_literal: true require 'active_support/core_ext/hash/keys' require 'active_support/core_ext/hash/indifferent_access' require_relative './entry' class ActiveSet class Instructions attr_reader :hash def initialize(hash) @hash = hash.with_indifferent_access @flattened_hash = hash.flatten_keys.transform_keys { |k| k.map(&:to_s) } end def process_adapter(set:, adapter:) @flattened_hash.reduce(set) do |inner_set, (keypath, value)| instruction = Entry.new(keypath, value) output = adapter.new(inner_set, instruction).process remove_from_instruction_set(key: instruction.path) if output[:processed] output[:set] end end def get(keypath) @hash.dig(*keypath) end private def remove_from_instruction_set(key:) @flattened_hash.delete(key) end end end
Version data entries
5 entries across 5 versions & 1 rubygems