class Dhall::Record

Public Class Methods

decode(record) click to toggle source
# File lib/dhall/binary.rb, line 146
def self.decode(record)
        if record.empty?
                EmptyRecord.new
        else
                new(record: Hash[record.map { |k, v| [k, Dhall.decode(v)] }])
        end
end
for(record) click to toggle source
# File lib/dhall/ast.rb, line 748
def self.for(record)
        if record.empty?
                EmptyRecord.new
        else
                new(record: record)
        end
end

Public Instance Methods

==(other) click to toggle source
# File lib/dhall/ast.rb, line 822
def ==(other)
        other.respond_to?(:record) && record.to_a == other.record.to_a
end
[](k) click to toggle source
# File lib/dhall/ast.rb, line 773
def [](k)
        record[k.to_s]
end
as_json() click to toggle source
# File lib/dhall/ast.rb, line 834
def as_json
        [8, Hash[record.to_a.map { |k, v| [k, v.as_json] }.sort]]
end
deep_merge(other) click to toggle source
Calls superclass method Dhall::Expression#deep_merge
# File lib/dhall/ast.rb, line 802
def deep_merge(other)
        other = other.as_dhall
        return super unless other.is_a?(Record)

        with(record: Hash[record.merge(other.record) { |_, v1, v2|
                v1.deep_merge(v2)
        }.sort])
end
dig(*keys) click to toggle source
# File lib/dhall/ast.rb, line 790
def dig(*keys)
        if keys.empty?
                raise ArgumentError, "wrong number of arguments (given 0, expected 1+)"
        end

        key, *rest = keys.map(&:to_s)
        v = record.fetch(key) { return nil }
        return v if rest.empty?

        v.dig(*rest)
end
each(&block) click to toggle source
# File lib/dhall/ast.rb, line 756
def each(&block)
        record.each(&block)
        self
end
eql?(other) click to toggle source
# File lib/dhall/ast.rb, line 826
def eql?(other)
        self == other
end
fetch(k, default=nil, &block) click to toggle source
# File lib/dhall/ast.rb, line 777
def fetch(k, default=nil, &block)
        record.fetch(k.to_s, *default, &block)
end
keys() click to toggle source
# File lib/dhall/ast.rb, line 765
def keys
        record.keys
end
map(&block) click to toggle source
# File lib/dhall/ast.rb, line 818
def map(&block)
        with(record: Hash[record.map(&block)])
end
merge(other) click to toggle source
Calls superclass method Dhall::Expression#merge
# File lib/dhall/ast.rb, line 811
def merge(other)
        other = other.as_dhall
        return super unless other.is_a?(Record)

        with(record: Hash[record.merge(other.record).sort])
end
normalize() click to toggle source
# File lib/dhall/normalize.rb, line 312
def normalize
        with(record: Hash[
                record.map { |k, v| [k, v.nil? ? v : v.normalize] }.sort
        ])
end
shift(amount, name, min_index) click to toggle source
# File lib/dhall/normalize.rb, line 318
def shift(amount, name, min_index)
        with(record: Hash[
                record.map { |k, v|
                        [k, v.nil? ? v : v.shift(amount, name, min_index)]
                }.sort
        ])
end
slice(*keys) click to toggle source
# File lib/dhall/ast.rb, line 781
def slice(*keys)
        keys = keys.map(&:to_s)
        if record.respond_to?(:slice)
                self.class.for(record.slice(*keys))
        else
                self.class.for(record.select { |k, _| keys.include?(k) })
        end
end
substitute(var, with_expr) click to toggle source
# File lib/dhall/normalize.rb, line 326
def substitute(var, with_expr)
        with(record: Hash[
                record.map { |k, v|
                        [k, v.nil? ? v : v.substitute(var, with_expr)]
                }.sort
        ])
end
to_h() click to toggle source
# File lib/dhall/ast.rb, line 761
def to_h
        record
end
values() click to toggle source
# File lib/dhall/ast.rb, line 769
def values
        record.values
end
with(attrs) click to toggle source
# File lib/dhall/ast.rb, line 830
def with(attrs)
        self.class.new({ record: record }.merge(attrs))
end