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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(var) ⇒ EnvironmentVariable

Returns a new instance of EnvironmentVariable.



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

def initialize(var)
  @var = var
end

Instance Attribute Details

#varObject (readonly)

Returns the value of attribute var.



1364
1365
1366
# File 'lib/dhall/ast.rb', line 1364

def var
  @var
end

Class Method Details

.decode(var) ⇒ Object



1358
1359
1360
1361
1362
# File 'lib/dhall/ast.rb', line 1358

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

Instance Method Details

#as_jsonObject



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

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

#canonicalObject



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

def canonical
  self
end

#chain_onto(relative_to) ⇒ Object



1370
1371
1372
1373
1374
1375
1376
# File 'lib/dhall/ast.rb', line 1370

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

  self
end

#hashObject



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

def hash
  @var.hash
end

#originObject



1398
1399
1400
# File 'lib/dhall/ast.rb', line 1398

def origin
  "localhost"
end

#pathObject



1378
1379
1380
# File 'lib/dhall/ast.rb', line 1378

def path
  []
end

#real_pathObject



1390
1391
1392
# File 'lib/dhall/ast.rb', line 1390

def real_path
  self
end

#resolve(resolver) ⇒ Object



1394
1395
1396
# File 'lib/dhall/ast.rb', line 1394

def resolve(resolver)
  resolver.resolve_environment(self)
end

#to_sObject



1402
1403
1404
# File 'lib/dhall/ast.rb', line 1402

def to_s
  "env:#{as_json}"
end

#with(path:) ⇒ Object



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

def with(path:)
  Path.from_string(path.join("/"))
end