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_cbor, #to_proc, #|
Class Method Details
.decode(record) ⇒ Object
116
117
118
119
120
121
122
|
# File 'lib/dhall/binary.rb', line 116
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
500
501
502
503
504
505
506
|
# File 'lib/dhall/ast.rb', line 500
def self.for(types)
if types.empty?
EmptyRecordType.new
else
RecordType.new(record: types)
end
end
|
Instance Method Details
#==(other) ⇒ Object
530
531
532
|
# File 'lib/dhall/ast.rb', line 530
def ==(other)
other.respond_to?(:record) && record.to_a == other.record.to_a
end
|
#as_json ⇒ Object
538
539
540
|
# File 'lib/dhall/ast.rb', line 538
def as_json
[7, Hash[record.to_a.map { |k, v| [k, v.as_json] }.sort]]
end
|
#deep_merge_type(other) ⇒ Object
514
515
516
517
518
519
520
|
# File 'lib/dhall/ast.rb', line 514
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
534
535
536
|
# File 'lib/dhall/ast.rb', line 534
def eql?(other)
self == other
end
|
#keys ⇒ Object
522
523
524
|
# File 'lib/dhall/ast.rb', line 522
def keys
record.keys
end
|
#merge_type(other) ⇒ Object
508
509
510
511
512
|
# File 'lib/dhall/ast.rb', line 508
def merge_type(other)
return self if other.is_a?(EmptyRecordType)
with(record: record.merge(other.record))
end
|
#slice(keys) ⇒ Object
526
527
528
|
# File 'lib/dhall/ast.rb', line 526
def slice(keys)
RecordType.for(record.select { |k, _| keys.include?(k) })
end
|