Sha256: 03570b82604bab687cf28354de784069124a1498b64d8155ad528665287fb0db

Contents?: true

Size: 1.15 KB

Versions: 78

Compression:

Stored size: 1.15 KB

Contents

module TomlRB
  class Table
    def initialize(dotted_keys)
      @dotted_keys = dotted_keys
    end

    def navigate_keys(hash, visited_keys, symbolize_keys = false)
      ensure_key_not_defined(visited_keys)
      current = hash
      keys = symbolize_keys ? @dotted_keys.map(&:to_sym) : @dotted_keys
      keys.each do |key|
        current[key] = {} unless current.key?(key)
        element = current[key]
        current = element.is_a?(Array) ? element.last : element
        # check that key has not been defined before as a scalar value
        fail ValueOverwriteError.new(key) unless current.is_a?(Hash)
      end
      current
    end

    def accept_visitor(parser)
      parser.visit_table self
    end

    def full_key
      @dotted_keys.join(".")
    end

    private

    # Fail if the key was already defined with a ValueOverwriteError
    def ensure_key_not_defined(visited_keys)
      fail ValueOverwriteError.new(full_key) if visited_keys.include?(full_key)
      visited_keys << full_key
    end
  end

  # Used in document.citrus
  module TableParser
    def value
      TomlRB::Table.new(captures[:stripped_key].map(&:value).first)
    end
  end
end

Version data entries

78 entries across 78 versions & 2 rubygems

Version Path
harbr-2.8.1 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
toml-rb-3.0.1 lib/toml-rb/table.rb
toml-rb-3.0.0 lib/toml-rb/table.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb
harbr-0.1.94 vendor/bundle/ruby/3.2.0/gems/toml-rb-2.2.0/lib/toml-rb/table.rb