Class: Dhall::RecordType
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Expression
#&, #*, #+, #as_dhall, #cache_key, #call, #concat, #deep_merge, #dhall_eq, #digest, #fetch, #fusion, #merge, #normalize, #resolve, #shift, #substitute, #to_binary, #to_cbor, #to_proc, #to_s, #|
Class Method Details
.decode(record) ⇒ Object
136
137
138
139
140
141
142
|
# File 'lib/dhall/binary.rb', line 136
def self.decode(record)
if record.empty?
EmptyRecordType.new
else
new(record: Hash[record.map { |k, v| [k, Dhall.decode(v)] }])
end
end
|
.for(types) ⇒ Object
633
634
635
636
637
638
639
|
# File 'lib/dhall/ast.rb', line 633
def self.for(types)
if types.empty?
EmptyRecordType.new
else
RecordType.new(record: types)
end
end
|
Instance Method Details
#==(other) ⇒ Object
663
664
665
|
# File 'lib/dhall/ast.rb', line 663
def ==(other)
other.respond_to?(:record) && record.to_a == other.record.to_a
end
|
#as_json ⇒ Object
671
672
673
|
# File 'lib/dhall/ast.rb', line 671
def as_json
[7, Hash[record.to_a.map { |k, v| [k, v.as_json] }.sort]]
end
|
#deep_merge_type(other) ⇒ Object
647
648
649
650
651
652
653
|
# File 'lib/dhall/ast.rb', line 647
def deep_merge_type(other)
return super unless other.class == RecordType
with(record: Hash[record.merge(other.record) { |_, v1, v2|
v1.deep_merge_type(v2)
}.sort])
end
|
#eql?(other) ⇒ Boolean
667
668
669
|
# File 'lib/dhall/ast.rb', line 667
def eql?(other)
self == other
end
|
#keys ⇒ Object
655
656
657
|
# File 'lib/dhall/ast.rb', line 655
def keys
record.keys
end
|
#merge_type(other) ⇒ Object
641
642
643
644
645
|
# File 'lib/dhall/ast.rb', line 641
def merge_type(other)
return self if other.is_a?(EmptyRecordType)
with(record: record.merge(other.record))
end
|
#slice(keys) ⇒ Object
659
660
661
|
# File 'lib/dhall/ast.rb', line 659
def slice(keys)
RecordType.for(record.select { |k, _| keys.include?(k) })
end
|