Class: Dependabot::DependencyFile

Inherits:
Object
  • Object
show all
Defined in:
lib/dependabot/dependency_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, content:, directory: "/", type: "file", support_file: false, symlink_target: nil) ⇒ DependencyFile

Returns a new instance of DependencyFile.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dependabot/dependency_file.rb', line 10

def initialize(name:, content:, directory: "/", type: "file",
               support_file: false, symlink_target: nil)
  @name = name
  @content = content
  @directory = clean_directory(directory)
  @symlink_target = symlink_target
  @support_file = support_file

  # Type is used *very* sparingly. It lets the git_modules updater know that
  # a "file" is actually a submodule, and lets our Go updaters know which
  # file represents the main.go.
  # New use cases should be avoided if at all possible (and use the
  # support_file flag instead)
  @type = type

  return unless (type == "symlink") ^ symlink_target

  raise "Symlinks must specify a target!" unless symlink_target
  raise "Only symlinked files must specify a target!" if symlink_target
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/dependabot/dependency_file.rb', line 7

def content
  @content
end

#directoryObject

Returns the value of attribute directory.



7
8
9
# File 'lib/dependabot/dependency_file.rb', line 7

def directory
  @directory
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/dependabot/dependency_file.rb', line 7

def name
  @name
end

#support_fileObject

Returns the value of attribute support_file.



7
8
9
# File 'lib/dependabot/dependency_file.rb', line 7

def support_file
  @support_file
end

Returns the value of attribute symlink_target.



7
8
9
# File 'lib/dependabot/dependency_file.rb', line 7

def symlink_target
  @symlink_target
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/dependabot/dependency_file.rb', line 7

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/dependabot/dependency_file.rb', line 48

def ==(other)
  return false unless other.instance_of?(self.class)

  my_hash = to_h.reject { |k| k == "support_file" }
  their_hash = other.to_h.reject { |k| k == "support_file" }
  my_hash == their_hash
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/dependabot/dependency_file.rb', line 60

def eql?(other)
  self.==(other)
end

#hashObject



56
57
58
# File 'lib/dependabot/dependency_file.rb', line 56

def hash
  to_h.hash
end

#pathObject



44
45
46
# File 'lib/dependabot/dependency_file.rb', line 44

def path
  Pathname.new(File.join(directory, name)).cleanpath.to_path
end

#support_file?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/dependabot/dependency_file.rb', line 64

def support_file?
  @support_file
end

#to_hObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dependabot/dependency_file.rb', line 31

def to_h
  details = {
    "name" => name,
    "content" => content,
    "directory" => directory,
    "type" => type,
    "support_file" => support_file
  }

  details["symlink_target"] = symlink_target if symlink_target
  details
end