Class: Dhall::Import

Inherits:
Expression show all
Defined in:
lib/dhall/ast.rb,
lib/dhall/binary.rb

Defined Under Namespace

Classes: AbsolutePath, AsLocation, EnvironmentVariable, Expression, Http, Https, IntegrityCheck, MissingImport, NoIntegrityCheck, Path, RelativePath, RelativeToHomePath, RelativeToParentPath, Text, URI

Constant Summary collapse

Location =
LazyObject.new do
	UnionType.new(
		alternatives: {
			"Local"       => Builtins[:Text],
			"Remote"      => Builtins[:Text],
			"Environment" => Builtins[:Text],
			"Missing"     => nil
		}
	)
end
IMPORT_TYPES =
[
	Expression,
	Text,
	AsLocation
].freeze
PATH_TYPES =
[
	Http, Https,
	AbsolutePath, RelativePath, RelativeToParentPath, RelativeToHomePath,
	EnvironmentVariable, MissingImport
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#&, #*, #+, #annotate, #as_dhall, #call, #concat, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #normalize, #resolve, #shift, #slice, #substitute, #to_binary, #to_cbor, #to_proc, #to_s, #|

Constructor Details

#initialize(integrity_check, import_type, path) ⇒ Import

Returns a new instance of Import.



1723
1724
1725
1726
1727
1728
1729
# File 'lib/dhall/ast.rb', line 1723

def initialize(integrity_check, import_type, path)
	super(
		integrity_check: integrity_check || NoIntegrityCheck.new,
		import_type:     import_type,
		path:            path
	)
end

Class Method Details

.decode(integrity_check, import_type, path_type, *parts) ⇒ Object



265
266
267
268
269
270
271
272
273
274
# File 'lib/dhall/binary.rb', line 265

def self.decode(integrity_check, import_type, path_type, *parts)
	parts[0] = Dhall.decode(parts[0]) if path_type < 2 && !parts[0].nil?
	path_type = PATH_TYPES.fetch(path_type)

	new(
		IntegrityCheck.decode(integrity_check),
		IMPORT_TYPES[import_type],
		path_type.decode(*parts)
	)
end

Instance Method Details

#as_jsonObject



1758
1759
1760
1761
1762
1763
1764
1765
1766
# File 'lib/dhall/ast.rb', line 1758

def as_json
	[
		24,
		integrity_check&.as_json,
		IMPORT_TYPES.index(import_type),
		PATH_TYPES.index(path.class),
		*path.as_json
	]
end

#cache_key(relative_to) ⇒ Object



1749
1750
1751
1752
1753
1754
1755
1756
# File 'lib/dhall/ast.rb', line 1749

def cache_key(relative_to)
	key = integrity_check.to_s
	if key.empty?
		real_path(relative_to)
	else
		key
	end
end

#parse_resolve_check(raw, deadline: Util::NoDeadline.new, **kwargs) ⇒ Object



1743
1744
1745
1746
1747
# File 'lib/dhall/ast.rb', line 1743

def parse_resolve_check(raw, deadline: Util::NoDeadline.new, **kwargs)
	import_type.call(raw, deadline: deadline).resolve(**kwargs).then do |e|
		integrity_check.check(TypeChecker.annotate(e))
	end
end

#real_path(relative_to) ⇒ Object



1739
1740
1741
# File 'lib/dhall/ast.rb', line 1739

def real_path(relative_to)
	path.chain_onto(relative_to).canonical
end

#with(options) ⇒ Object



1731
1732
1733
1734
1735
1736
1737
# File 'lib/dhall/ast.rb', line 1731

def with(options)
	self.class.new(
		options.fetch(:integrity_check, integrity_check),
		options.fetch(:import_type, import_type),
		options.fetch(:path, path)
	)
end