Class: Dhall::Import::EnvironmentVariable
- Inherits:
-
Object
- Object
- Dhall::Import::EnvironmentVariable
- 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
- #as_json ⇒ Object
- #canonical ⇒ Object
- #chain_onto(relative_to) ⇒ Object
-
#initialize(var) ⇒ EnvironmentVariable
constructor
A new instance of EnvironmentVariable.
- #origin ⇒ Object
- #real_path ⇒ Object
- #resolve(resolver) ⇒ Object
- #to_s ⇒ Object
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
Instance Method Details
#as_json ⇒ Object
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 |
#canonical ⇒ Object
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 |
#origin ⇒ Object
1367 1368 1369 |
# File 'lib/dhall/ast.rb', line 1367 def origin "localhost" end |
#real_path ⇒ Object
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_s ⇒ Object
1371 1372 1373 |
# File 'lib/dhall/ast.rb', line 1371 def to_s "env:#{as_json}" end |