Sha256: a5fd8f2a2fe918701cb93909457e8711f55471fd6c7ab1cca6014277d2421caf

Contents?: true

Size: 955 Bytes

Versions: 1

Compression:

Stored size: 955 Bytes

Contents

# frozen_string_literal: true

require 'eac_config/entry'
require 'eac_config/paths_hash'

module EacConfig
  class EntrySearch
    enable_simple_cache
    common_constructor :node, :path

    private

    def result_from_load_path_uncached
      node.recursive_loaded_nodes.lazy.map { |loaded_node| loaded_node.entry(path) }.find(&:found?)
    end

    def result_from_self_uncached
      return nil unless paths_hash.key?(to_paths_hash_key)

      ::EacConfig::Entry.new(node, path, true, paths_hash.fetch(to_paths_hash_key))
    end

    def result_not_found_uncached
      ::EacConfig::Entry.new(nil, path, false, nil)
    end

    # @return [EacConfig::Entry]
    def result_uncached
      result_from_self || result_from_load_path || result_not_found
    end

    # @return [EacConfig::PathsHash]
    def paths_hash_uncached
      ::EacConfig::PathsHash.new(node.data)
    end

    def to_paths_hash_key
      path.parts.join('.')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
eac_config-0.2.0 lib/eac_config/entry_search.rb