Class: Literal::Types::MapType Private
- Inherits:
-
Object
- Object
- Literal::Types::MapType
- Includes:
- Literal::Type
- Defined in:
- lib/literal/types/map_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.
Instance Attribute Summary collapse
- #shape ⇒ Object readonly private
Instance Method Summary collapse
- #===(other) ⇒ Object private
- #>=(other) ⇒ Object private
-
#initialize(shape) ⇒ MapType
constructor
private
A new instance of MapType.
- #inspect ⇒ Object private
- #record_literal_type_errors(context) ⇒ Object private
Constructor Details
#initialize(shape) ⇒ MapType
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.
Returns a new instance of MapType.
7 8 9 10 |
# File 'lib/literal/types/map_type.rb', line 7 def initialize(shape) @shape = shape freeze end |
Instance Attribute Details
#shape ⇒ Object (readonly)
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.
12 13 14 |
# File 'lib/literal/types/map_type.rb', line 12 def shape @shape end |
Instance Method Details
#===(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.
18 19 20 21 22 |
# File 'lib/literal/types/map_type.rb', line 18 def ===(other) Hash === other && @shape.each do |k, v| return false unless v === other[k] 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.
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/literal/types/map_type.rb', line 42 def >=(other) case other when Literal::Types::MapType other_shape = other.shape @shape.all? do |k, v| Literal.subtype?(other_shape[k], v) end else false end end |
#inspect ⇒ 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.
14 15 16 |
# File 'lib/literal/types/map_type.rb', line 14 def inspect "_Map(#{@shape.inspect})" end |
#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.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/literal/types/map_type.rb', line 24 def record_literal_type_errors(context) unless Hash === context.actual return end @shape.each do |key, expected| unless context.actual.key?(key) || expected === nil context.add_child(label: "[#{key.inspect}]", expected:, actual: nil) next end actual = context.actual[key] unless expected === actual context.add_child(label: "[#{key.inspect}]", expected:, actual:) end end end |