Class: Dhall::Import::EnvironmentVariable

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

Constant Summary collapse

ESCAPES =
{
	"\"" => "\"",
	"\\" => "\\",
	"a"  => "\a",
	"b"  => "\b",
	"f"  => "\f",
	"n"  => "\n",
	"r"  => "\r",
	"t"  => "\t",
	"v"  => "\v"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var) ⇒ EnvironmentVariable

Returns a new instance of EnvironmentVariable.



1334
1335
1336
# File 'lib/dhall/ast.rb', line 1334

def initialize(var)
	@var = var
end

Class Method Details

.decode(var) ⇒ Object



1328
1329
1330
1331
1332
# File 'lib/dhall/ast.rb', line 1328

def self.decode(var)
	var.gsub(/\\[\"\\abfnrtv]/) do |escape|
		ESCAPES.fetch(escape[1])
	end
end

Instance Method Details

#as_jsonObject



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

def as_json
	@var.gsub(/[\"\\\a\b\f\n\r\t\v]/) do |c|
		"\\" + ESCAPES.find { |(_, v)| v == c }.first
	end
end

#canonicalObject



1346
1347
1348
# File 'lib/dhall/ast.rb', line 1346

def canonical
	real_path.canonical
end

#chain_onto(relative_to) ⇒ Object



1338
1339
1340
1341
1342
1343
1344
# File 'lib/dhall/ast.rb', line 1338

def chain_onto(relative_to)
	if relative_to.is_a?(URI)
		raise ImportBannedException, "remote import cannot import #{self}"
	end

	real_path.chain_onto(relative_to)
end

#originObject



1367
1368
1369
# File 'lib/dhall/ast.rb', line 1367

def origin
	"localhost"
end

#real_pathObject



1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
# File 'lib/dhall/ast.rb', line 1350

def real_path
	val = ENV.fetch(@var) do
		raise ImportFailedException, "No #{self}"
	end
	if val =~ /\Ahttps?:\/\//
		URI.from_uri(URI(val))
	else
		Path.from_string(val)
	end
end

#resolve(resolver) ⇒ Object



1361
1362
1363
1364
1365
# File 'lib/dhall/ast.rb', line 1361

def resolve(resolver)
	Promise.resolve(nil).then do
		real_path.resolve(resolver)
	end
end

#to_sObject



1371
1372
1373
# File 'lib/dhall/ast.rb', line 1371

def to_s
	"env:#{as_json}"
end