Class: Dhall::Import::URI

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

Direct Known Subclasses

Http, Https

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decode(headers, authority, *path, query) ⇒ Object



230
231
232
233
234
235
236
237
238
# File 'lib/dhall/binary.rb', line 230

def self.decode(headers, authority, *path, query)
	uri = ::URI.scheme_list[name.split(/::/).last.upcase].build(
		Parser.parse(authority, root: :authority).value.merge(
			path: Util.path_components_to_uri(*path).path
		)
	)
	uri.instance_variable_set(:@query, query)
	new(headers: headers, uri: uri)
end

Instance Method Details

#as_jsonObject



1410
1411
1412
# File 'lib/dhall/ast.rb', line 1410

def as_json
	[@headers&.as_json, authority, *path, uri.query]
end

#authorityObject



1385
1386
1387
1388
1389
1390
# File 'lib/dhall/ast.rb', line 1385

def authority
	[
		uri.userinfo,
		[uri.host, port].compact.join(":")
	].compact.join("@")
end

#canonicalObject



1373
1374
1375
1376
1377
1378
1379
# File 'lib/dhall/ast.rb', line 1373

def canonical
	with(
		path: (path[1..-1] + [""]).reduce([[], path.first]) { |(pth, prev), c|
			c == ".." ? [pth, prev] : [pth + [prev], c]
		}.first.reject { |c| c == "." }
	)
end

#chain_onto(relative_to) ⇒ Object



1365
1366
1367
1368
1369
1370
1371
# File 'lib/dhall/ast.rb', line 1365

def chain_onto(relative_to)
	if headers.is_a?(Import)
		with(headers: headers.with(path: headers.real_path(relative_to)))
	else
		self
	end
end

#headersObject



1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
# File 'lib/dhall/ast.rb', line 1354

def headers
	header_type = RecordType.new(
		record: {
			"mapKey"   => Builtins[:Text],
			"mapValue" => Builtins[:Text]
		}
	)

	super || EmptyList.new(element_type: header_type)
end

#locationObject



1400
1401
1402
# File 'lib/dhall/ast.rb', line 1400

def location
	Union.from(Location, "Remote", to_s.as_dhall)
end

#originObject



1392
1393
1394
# File 'lib/dhall/ast.rb', line 1392

def origin
	"#{uri.scheme}://#{authority}"
end

#pathObject



1404
1405
1406
1407
1408
# File 'lib/dhall/ast.rb', line 1404

def path
	path = uri.path.split(/\//, -1).map(&::URI.method(:unescape))
	path = path[1..-1] if path.length > 1 && path.first.empty?
	path
end

#portObject



1381
1382
1383
# File 'lib/dhall/ast.rb', line 1381

def port
	uri.port && uri.port != uri.default_port ? uri.port : nil
end

#to_sObject



1396
1397
1398
# File 'lib/dhall/ast.rb', line 1396

def to_s
	uri.to_s
end

#with(attrs) ⇒ Object



1345
1346
1347
1348
1349
1350
1351
1352
# File 'lib/dhall/ast.rb', line 1345

def with(attrs)
	if attrs.key?(:path)
		attrs[:uri] =
			uri + Util.path_components_to_uri(*attrs.delete(:path))
	end

	super
end