Sha256: c0ecb0e3f775c947006d5bbb9d26552bfaa8d9efcf3662e2a1fbb9437e514208

Contents?: true

Size: 1.01 KB

Versions: 69

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacConfig
  class EntryPath
    PART_SEPARATOR = '.'

    class << self
      def assert(source)
        source.is_a?(self) ? source : new(build_parts(source))
      end

      def build_parts(source)
        return validate_parts!(source.split(PART_SEPARATOR)) if source.is_a?(::String)
        return validate_parts!(source.flat_map { |part| build_parts(part) }) if
        source.is_a?(::Enumerable)

        build_parts(source.to_s)
      end

      def validate_parts!(parts)
        parts.assert_argument(::Enumerable, 'parts')
        parts.each_with_index do |part, index|
          raise ::ArgumentError, "Part #{index} of #{parts} is blank" if part.blank?
          raise ::ArgumentError, "Part #{index} is not a string" unless part.is_a?(::String)
        end
      end
    end

    attr_reader :parts

    def initialize(parts)
      @parts = parts.to_a.freeze
    end

    def to_s
      "#{self.class}[#{parts.join(PART_SEPARATOR)}]"
    end
  end
end

Version data entries

69 entries across 69 versions & 4 rubygems

Version Path
eac_tools-0.7.0 sub/avm-tools/sub/eac_config/lib/eac_config/entry_path.rb
eac_tools-0.6.0 sub/avm-tools/sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.121.2 sub/eac_config/lib/eac_config/entry_path.rb
eac_tools-0.5.0 sub/avm-tools/sub/eac_config/lib/eac_config/entry_path.rb
eac_tools-0.4.0 sub/avm-tools/sub/eac_config/lib/eac_config/entry_path.rb
eac_tools-0.3.0 sub/avm-tools/sub/eac_config/lib/eac_config/entry_path.rb
eac_tools-0.2.2 sub/avm-tools/sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.121.1 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.121.0 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.120.2 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.120.1 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.120.0 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.119.0 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.118.0 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.117.3 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.117.2 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.117.1 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.117.0 sub/eac_config/lib/eac_config/entry_path.rb
avm-tools-0.116.2 sub/eac_config/lib/eac_config/entry_path.rb
eac_config-0.8.1 lib/eac_config/entry_path.rb