Class: Literal::Types::JSONDataType Private

Inherits:
Object
  • Object
show all
Includes:
Literal::Type
Defined in:
lib/literal/types/json_data_type.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

Instance =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

new.freeze
COMPATIBLE_TYPES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Set[
	Integer,
	Float,
	String,
	true,
	false,
	nil,
	Literal::Types::BooleanType::Instance,
	Instance
].freeze

Instance Method Summary collapse

Instance Method Details

#===(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/literal/types/json_data_type.rb', line 22

def ===(value)
	case value
	when String, Integer, Float, true, false, nil
		true
	when Hash
		value.each do |k, v|
			return false unless String === k && self === v
		end
	when Array
		value.all?(self)
	else
		false
	end
end

#>=(other) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/literal/types/json_data_type.rb', line 53

def >=(other)
	return true if COMPATIBLE_TYPES.include?(other)

	case other
	when Literal::Types::ArrayType
		self >= other.type
	when Literal::Types::HashType
		(self >= other.key_type) && (self >= other.value_type)
	when Literal::Types::ConstraintType
		other.object_constraints.any? { |type| self >= type }
	else
		false
	end
end

#inspectObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



20
# File 'lib/literal/types/json_data_type.rb', line 20

def inspect = "_JSONData"

#record_literal_type_errors(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/literal/types/json_data_type.rb', line 37

def record_literal_type_errors(context)
	case value = context.actual
	when String, Integer, Float, true, false, nil
		# nothing to do
	when Hash
		value.each do |k, v|
			context.add_child(label: "[]", expected: String, actual: k) unless String === k
			context.add_child(label: "[#{k.inspect}]", expected: self, actual: v) unless self === v
		end
	when Array
		value.each_with_index do |item, index|
			context.add_child(label: "[#{index}]", expected: self, actual: item) unless self === item
		end
	end
end