class StructureDigest::SchemaParts::AbstractPath

Attributes

parts[R]

Public Class Methods

from_shorthand(shorthand) click to toggle source
# File lib/structure_digest/abstract_path.rb, line 20
def self.from_shorthand(shorthand)
  shorthand = orig_shorthand.clone
  abstract_path = AbstractPath.new
  while !shorthand.empty?
    if key = shorthand[/^\.(\w+)/, 1]
      abstract_path = abstract_path.add_part(HashDereference.new(key))
      shorthand.sub!(/^\.\w+/, '')
    elsif shorthand[/^\[\]/]
      abstract_path = abstract_path.add_part(AbstractArrayDereference.new)
      shorthand.sub!("[]", '')
    else
      raise "shorthand #{shorthand} isn't a valid path shorthand"
    end
  end
  abstract_path
end
new(abstract_parts) click to toggle source
# File lib/structure_digest/abstract_path.rb, line 4
def initialize(abstract_parts)
  @parts = abstract_parts
end

Public Instance Methods

==(other) click to toggle source
# File lib/structure_digest/abstract_path.rb, line 38
def ==(other)
  self.class == other.class && @parts == other.parts
end
Also aliased as: eql?
accepts(path) click to toggle source
# File lib/structure_digest/abstract_path.rb, line 12
def accepts(path)
  self == path.abstract
end
add_part(part) click to toggle source
# File lib/structure_digest/abstract_path.rb, line 16
def add_part(part)
  AbstractPath.new(@parts + [part])
end
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/structure_digest/abstract_path.rb, line 42
def hash; [@parts].hash; end
serialize() click to toggle source
# File lib/structure_digest/abstract_path.rb, line 8
def serialize
  @parts.map(&:serialize).join
end