Class: Puppet::Pops::Types::Mismatch

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/types/type_mismatch_describer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Mismatch

Returns a new instance of Mismatch.



71
72
73
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 71

def initialize(path)
  @path = path || EMPTY_ARRAY
end

Instance Attribute Details

#pathObject (readonly)



69
70
71
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 69

def path
  @path
end

Instance Method Details

#==(o) ⇒ Object Also known as: eql?



87
88
89
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 87

def ==(o)
  self.class == o.class && canonical_path == o.canonical_path
end

#canonical_pathObject



75
76
77
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 75

def canonical_path
  @canonical_path ||= @path.reject { |e| e.is_a?(VariantPathElement) }
end

#chop_path(element_index) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 97

def chop_path(element_index)
  return self if element_index >= @path.size
  chopped_path = @path.clone
  chopped_path.delete_at(element_index)
  copy = self.clone
  copy.instance_variable_set(:@path, chopped_path)
  copy
end

#hashObject



93
94
95
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 93

def hash
  canonical_path.hash
end

#merge(path, o) ⇒ Object



83
84
85
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 83

def merge(path, o)
  self.class.new(path)
end

#message(variant, position) ⇒ Object



79
80
81
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 79

def message(variant, position)
  "#{variant}unknown mismatch#{position}"
end

#path_stringObject



106
107
108
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 106

def path_string
  @path.join(' ')
end

#to_sObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 110

def to_s
  p = @path
  variant = ''
  position = ''
  unless p.empty?
    f = p.first
    if f.is_a?(SignaturePathElement)
      variant = " #{f}"
      p = p.drop(1)
    end
    position = " #{p.join(' ')}" unless p.empty?
  end
  message(variant, position)
end