Class: Dependabot::Nix::Lockfile

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dependabot/nix/lockfile.rb

Constant Summary collapse

Node =
T.type_alias { T::Hash[String, Object] }

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Lockfile

Returns a new instance of Lockfile.



15
16
17
# File 'lib/dependabot/nix/lockfile.rb', line 15

def initialize(content)
  @data = T.let(T.cast(JSON.parse(content), Node), Node)
end

Instance Method Details

#input_node(input_name) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/dependabot/nix/lockfile.rb', line 40

def input_node(input_name)
  label = resolve_reference(root_inputs[input_name], T.let(Set.new, T::Set[String]))
  return unless label

  node = nodes[label]
  node if node.is_a?(Hash)
end

#input_path(input_name) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/dependabot/nix/lockfile.rb', line 31

def input_path(input_name)
  reference = root_inputs[input_name]
  return [input_name] if reference.is_a?(String)
  return unless string_array?(reference)

  T.cast(reference, T::Array[String])
end

#locked_revision(input_name) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/dependabot/nix/lockfile.rb', line 61

def locked_revision(input_name)
  locked = locked_source(input_name)
  return unless locked

  revision = locked["rev"]
  revision if revision.is_a?(String)
end

#locked_source(input_name) ⇒ Object



55
56
57
58
# File 'lib/dependabot/nix/lockfile.rb', line 55

def locked_source(input_name)
  locked = input_node(input_name)&.fetch("locked", nil)
  locked if locked.is_a?(Hash)
end

#original_source(input_name) ⇒ Object



49
50
51
52
# File 'lib/dependabot/nix/lockfile.rb', line 49

def original_source(input_name)
  original = input_node(input_name)&.fetch("original", nil)
  original if original.is_a?(Hash)
end

#root_input_namesObject



26
27
28
# File 'lib/dependabot/nix/lockfile.rb', line 26

def root_input_names
  root_inputs.keys
end

#versionObject



20
21
22
23
# File 'lib/dependabot/nix/lockfile.rb', line 20

def version
  value = @data["version"]
  value if value.is_a?(Integer)
end