Sha256: 6d3178b560c218bc1b997e64acb271cff1d42cdcab7906594f238441e9ad33a6

Contents?: true

Size: 1.37 KB

Versions: 36

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacConfig
  class PathsHash
    require_sub __FILE__

    class << self
      def parse_entry_key(entry_key)
        r = entry_key.to_s.strip
        raise ::EacConfig::PathsHash::EntryKeyError, 'Entry key cannot start or end with dot' if
        r.start_with?('.') || r.end_with?('.')

        r = r.split('.').map(&:strip)
        if r.empty?
          raise ::EacConfig::PathsHash::EntryKeyError, "Entry key \"#{entry_key}\" is empty"
        end
        return r.map(&:to_sym) unless r.any?(&:blank?)

        raise ::EacConfig::PathsHash::EntryKeyError,
              "Entry key \"#{entry_key}\" has at least one blank part"
      end
    end

    attr_reader :root

    def initialize(source_hash = {})
      @root = Node.new(source_hash)
    end

    def [](entry_key)
      root.read_entry(::EacConfig::PathsHash::PathSearch.parse_entry_key(entry_key))
    end

    def []=(entry_key, entry_value)
      root.write_entry(
        ::EacConfig::PathsHash::PathSearch.parse_entry_key(entry_key), entry_value
      )
    end

    def fetch(entry_key)
      root.fetch(::EacConfig::PathsHash::PathSearch.parse_entry_key(entry_key))
    end

    def key?(entry_key)
      root.entry?(::EacConfig::PathsHash::PathSearch.parse_entry_key(entry_key))
    end

    delegate :to_h, to: :root

    private

    attr_reader :data
  end
end

Version data entries

36 entries across 36 versions & 3 rubygems

Version Path
eac_config-0.5.2 lib/eac_config/paths_hash.rb
ehbrs-tools-0.28.3 vendor/eac_config/lib/eac_config/paths_hash.rb
avm-tools-0.110.0 vendor/eac_config/lib/eac_config/paths_hash.rb
avm-tools-0.109.1 vendor/eac_config/lib/eac_config/paths_hash.rb
avm-tools-0.109.0 vendor/eac_config/lib/eac_config/paths_hash.rb
ehbrs-tools-0.28.2 vendor/eac_config/lib/eac_config/paths_hash.rb
avm-tools-0.108.0 vendor/eac_config/lib/eac_config/paths_hash.rb
ehbrs-tools-0.28.1 vendor/eac_config/lib/eac_config/paths_hash.rb
avm-tools-0.107.0 vendor/eac_config/lib/eac_config/paths_hash.rb
ehbrs-tools-0.28.0 vendor/eac_config/lib/eac_config/paths_hash.rb
avm-tools-0.106.0 vendor/eac_config/lib/eac_config/paths_hash.rb
ehbrs-tools-0.27.0 vendor/eac_config/lib/eac_config/paths_hash.rb
ehbrs-tools-0.26.0 vendor/eac_config/lib/eac_config/paths_hash.rb
avm-tools-0.105.0 vendor/eac_config/lib/eac_config/paths_hash.rb
ehbrs-tools-0.25.1 vendor/eac_config/lib/eac_config/paths_hash.rb
ehbrs-tools-0.25.0 vendor/eac_config/lib/eac_config/paths_hash.rb
ehbrs-tools-0.24.0 vendor/eac_config/lib/eac_config/paths_hash.rb
eac_config-0.5.1 lib/eac_config/paths_hash.rb
avm-tools-0.104.0 vendor/eac_config/lib/eac_config/paths_hash.rb
ehbrs-tools-0.23.1 vendor/eac_config/lib/eac_config/paths_hash.rb