Class: PrimitiveTypeValidation

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

#typeObject (readonly)

Returns the value of attribute type.



1092
1093
1094
# File 'lib/json_patterns.rb', line 1092

def type
  @type
end

Instance Method Details

#to_sObject



1106
1107
1108
# File 'lib/json_patterns.rb', line 1106

def to_s
  @type.to_s
end

#validate(path, data) ⇒ Object



1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
# File 'lib/json_patterns.rb', line 1094

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