Class: PrimitiveValueValidation

Inherits:
Validation show all
Defined in:
lib/json_patterns.rb

Constant Summary

Constants included from Inspectable

Inspectable::INSPECTING_KEY

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Validation

#as_object_members, #expects_an_object?, memoized_new_from_pattern, new_from_pattern, #shallow_describe, #shallow_match?, #validate_from_root

Methods included from HashInitialized

#initialize

Methods included from DeepEquality

#==

Methods included from Inspectable

#inspect

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



1112
1113
1114
# File 'lib/json_patterns.rb', line 1112

def value
  @value
end

Instance Method Details

#to_sObject



1130
1131
1132
1133
1134
1135
1136
1137
# File 'lib/json_patterns.rb', line 1130

def to_s
  case @value
  when nil
    'null'
  else
    @value.inspect
  end
end

#validate(path, data) ⇒ Object



1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
# File 'lib/json_patterns.rb', line 1114

def validate(path, data)
  if JsonType.new_from_value(@value) === data
    if data == @value
      return []
    else
      return [ValidationUnexpected.new(path: path, expected: to_s, found: data.inspect)]
    end
  else
    return [ValidationUnexpected.new(
      path: path,
      expected: json_type_name(@value),
      found: JsonType.new_from_value(data).to_s,
    )]
  end
end