Class: Dhall::Import

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

Defined Under Namespace

Classes: AbsolutePath, EnvironmentVariable, Expression, Http, Https, IntegrityCheck, MissingImport, Path, RelativePath, RelativeToHomePath, RelativeToParentPath, Text, URI

Constant Summary collapse

IMPORT_TYPES =
[
  Expression,
  Text
].freeze
PATH_TYPES =
[
  Http, Https,
  AbsolutePath, RelativePath, RelativeToParentPath, RelativeToHomePath,
  EnvironmentVariable, MissingImport
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#&, #*, #+, #as_dhall, #call, #concat, #deep_merge, #deep_merge_type, #dhall_eq, #digest, #fetch, #fusion, #merge, #normalize, #resolve, #shift, #slice, #substitute, #to_cbor, #to_proc, #to_s, #|

Constructor Details

#initialize(integrity_check, import_type, path) ⇒ Import



1545
1546
1547
1548
1549
1550
1551
# File 'lib/dhall/ast.rb', line 1545

def initialize(integrity_check, import_type, path)
  super(
    integrity_check: integrity_check || IntegrityCheck.new,
    import_type:     import_type,
    path:            path
  )
end

Class Method Details

.decode(integrity_check, import_type, path_type, *parts) ⇒ Object



193
194
195
196
197
198
199
200
201
# File 'lib/dhall/binary.rb', line 193

def self.decode(integrity_check, import_type, path_type, *parts)
  parts[0] = Dhall.decode(parts[0]) if path_type < 2 && !parts[0].nil?

  new(
    IntegrityCheck.new(*integrity_check),
    IMPORT_TYPES[import_type],
    PATH_TYPES[path_type].new(*parts)
  )
end

Instance Method Details

#as_jsonObject



1577
1578
1579
1580
1581
1582
1583
1584
1585
# File 'lib/dhall/ast.rb', line 1577

def as_json
  [
    24,
    integrity_check&.as_json,
    IMPORT_TYPES.index(import_type),
    PATH_TYPES.index(path.class),
    *path.as_json
  ]
end

#cache_key(relative_to) ⇒ Object



1569
1570
1571
1572
1573
1574
1575
# File 'lib/dhall/ast.rb', line 1569

def cache_key(relative_to)
  if integrity_check.protocol == :nocheck
    real_path(relative_to)
  else
    integrity_check.to_s
  end
end

#parse_and_check(raw, deadline: Util::NoDeadline.new) ⇒ Object



1565
1566
1567
# File 'lib/dhall/ast.rb', line 1565

def parse_and_check(raw, deadline: Util::NoDeadline.new)
  integrity_check.check(import_type.call(raw, deadline: deadline))
end

#real_path(relative_to) ⇒ Object



1561
1562
1563
# File 'lib/dhall/ast.rb', line 1561

def real_path(relative_to)
  path.chain_onto(relative_to).canonical
end

#with(options) ⇒ Object



1553
1554
1555
1556
1557
1558
1559
# File 'lib/dhall/ast.rb', line 1553

def with(options)
  self.class.new(
    options.fetch(:integrity_check, integrity_check),
    options.fetch(:import_type, import_type),
    options.fetch(:path, path)
  )
end