Class: Puppet::Pops::Types::TypeMismatch
- Inherits:
-
ExpectedActualMismatch
- Object
- Mismatch
- ExpectedActualMismatch
- Puppet::Pops::Types::TypeMismatch
- Includes:
- LabelProvider
- Defined in:
- lib/puppet/pops/types/type_mismatch_describer.rb
Direct Known Subclasses
Constant Summary
Constants included from LabelProvider
LabelProvider::A, LabelProvider::AN, LabelProvider::SKIPPED_CHARACTERS, LabelProvider::VOWELS
Instance Attribute Summary
Attributes inherited from ExpectedActualMismatch
Attributes inherited from Mismatch
Instance Method Summary collapse
- #label(o) ⇒ Object
-
#merge(path, o) ⇒ Object
A new instance with the least restrictive respective boundaries.
- #message(variant, position) ⇒ Object
Methods included from LabelProvider
#a_an, #a_an_uc, #plural_s, #the, #the_uc
Methods inherited from ExpectedActualMismatch
Methods inherited from Mismatch
#==, #canonical_path, #chop_path, #hash, #initialize, #path_string, #to_s
Constructor Details
This class inherits a constructor from Puppet::Pops::Types::ExpectedActualMismatch
Instance Method Details
#label(o) ⇒ Object
246 247 248 |
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 246 def label(o) o.to_s end |
#merge(path, o) ⇒ Object
Returns A new instance with the least restrictive respective boundaries.
204 205 206 |
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 204 def merge(path, o) self.class.new(path, [expected, o.expected].flatten.uniq, actual) end |
#message(variant, position) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/puppet/pops/types/type_mismatch_describer.rb', line 208 def (variant, position) e = expected a = actual multi = false if e.is_a?(Array) # Use simple names when classes differ, or in other words, only include details # when the classes are equal. # if e.find { |t| t.class == a.class } e = e.map { |t| t.to_s } a = a.to_s else sns = e.map { |t| t.simple_name } e = e.map { |t| s = t.simple_name; sns.count {|x| x == s } == 1 ? s : t.to_s } a = a.simple_name end case e.size when 1 e = e[0] when 2 e = "#{e[0]} or #{e[1]}" multi = true else e = "#{e[0..e.size-2].join(', ')}, or #{e[e.size-1]}" multi = true end else if e.class != a.class e = e.simple_name a = a.simple_name else e = e.to_s a = a.to_s end end multi ? "#{variant}#{position} expects a value of type #{e}, got #{label(a)}" : "#{variant}#{position} expects #{a_an(e)} value, got #{label(a)}" end |