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



236
237
238
239
240
241
242
243
244
# File 'lib/dhall/binary.rb', line 236

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

Instance Method Details

#as_jsonObject



1460
1461
1462
# File 'lib/dhall/ast.rb', line 1460

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

#authorityObject



1435
1436
1437
1438
1439
1440
# File 'lib/dhall/ast.rb', line 1435

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

#canonicalObject



1423
1424
1425
1426
1427
1428
1429
# File 'lib/dhall/ast.rb', line 1423

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



1415
1416
1417
1418
1419
1420
1421
# File 'lib/dhall/ast.rb', line 1415

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



1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
# File 'lib/dhall/ast.rb', line 1404

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

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

#locationObject



1450
1451
1452
# File 'lib/dhall/ast.rb', line 1450

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

#originObject



1442
1443
1444
# File 'lib/dhall/ast.rb', line 1442

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

#pathObject



1454
1455
1456
1457
1458
# File 'lib/dhall/ast.rb', line 1454

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

#portObject



1431
1432
1433
# File 'lib/dhall/ast.rb', line 1431

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

#to_sObject



1446
1447
1448
# File 'lib/dhall/ast.rb', line 1446

def to_s
	uri.to_s
end

#with(attrs) ⇒ Object



1395
1396
1397
1398
1399
1400
1401
1402
# File 'lib/dhall/ast.rb', line 1395

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

	super
end