Sha256: eb2e351194e898f94c4ec46cdbea280dabc8f433b4e2af6e3fd7dfaf758b4e2e

Contents?: true

Size: 1.26 KB

Versions: 74

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require 'eac_config/entry_path'
require 'eac_ruby_utils/core_ext'

module EacConfig
  class Entry
    require_sub __FILE__
    enable_simple_cache
    common_constructor :root_node, :path do
      self.path = ::EacConfig::EntryPath.assert(path)
    end

    def found?
      node_entry.if_present(false, &:found?)
    end

    def found_node
      node_entry.if_present(&:node)
    end

    def secret_value
      node_entry.if_present(&:secret_value)
    end

    def to_s
      "#{self.class}[RootNode: #{root_node}, Path: #{path}]"
    end

    def value
      node_entry.if_present(&:value)
    end

    def value!
      return value if found?

      raise ::EacConfig::Entry::NotFoundError, self
    end

    def value=(a_value)
      write_node.self_entry(path).value = a_value
    end

    def write_node
      root_node.write_node || root_node
    end

    private

    def node_entry_uncached
      node_entry_from_root || node_entry_from_load_path
    end

    def node_entry_from_load_path_uncached
      root_node.recursive_loaded_nodes.lazy.map { |loaded_node| loaded_node.self_entry(path) }
        .find(&:found?)
    end

    def node_entry_from_root_uncached
      e = root_node.self_entry(path)
      e.found? ? e : nil
    end
  end
end

Version data entries

74 entries across 74 versions & 2 rubygems

Version Path
eac_config-0.14.3 lib/eac_config/entry.rb
eac_tools-0.97.2 sub/eac_config/lib/eac_config/entry.rb
eac_config-0.14.2 lib/eac_config/entry.rb
eac_tools-0.82.0 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.81.0 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.80.0 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.79.0 sub/eac_config/lib/eac_config/entry.rb
eac_config-0.14.1 lib/eac_config/entry.rb
eac_tools-0.78.0 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.77.1 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.77.0 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.76.1 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.76.0 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.75.2 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.75.1 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.75.0 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.74.1 sub/eac_config/lib/eac_config/entry.rb
eac_tools-0.74.0 sub/eac_config/lib/eac_config/entry.rb
eac_config-0.14.0 lib/eac_config/entry.rb
eac_tools-0.73.0 sub/eac_config/lib/eac_config/entry.rb