Class: Dependabot::DependencyFile
- Inherits:
-
Object
- Object
- Dependabot::DependencyFile
- Defined in:
- lib/dependabot/dependency_file.rb
Defined Under Namespace
Classes: ContentEncoding
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
-
#deleted ⇒ Object
Returns the value of attribute deleted.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#name ⇒ Object
Returns the value of attribute name.
-
#support_file ⇒ Object
Returns the value of attribute support_file.
-
#symlink_target ⇒ Object
Returns the value of attribute symlink_target.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #binary? ⇒ Boolean
- #decoded_content ⇒ Object
- #deleted? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name:, content:, directory: "/", type: "file", support_file: false, symlink_target: nil, content_encoding: ContentEncoding::UTF_8, deleted: false) ⇒ DependencyFile
constructor
A new instance of DependencyFile.
- #path ⇒ Object
- #support_file? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(name:, content:, directory: "/", type: "file", support_file: false, symlink_target: nil, content_encoding: ContentEncoding::UTF_8, deleted: false) ⇒ DependencyFile
Returns a new instance of DependencyFile.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dependabot/dependency_file.rb', line 15 def initialize(name:, content:, directory: "/", type: "file", support_file: false, symlink_target: nil, content_encoding: ContentEncoding::UTF_8, deleted: false) @name = name @content = content @directory = clean_directory(directory) @symlink_target = symlink_target @support_file = support_file @content_encoding = content_encoding @deleted = deleted # 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
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/dependabot/dependency_file.rb', line 7 def content @content end |
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
7 8 9 |
# File 'lib/dependabot/dependency_file.rb', line 7 def content_encoding @content_encoding end |
#deleted ⇒ Object
Returns the value of attribute deleted.
7 8 9 |
# File 'lib/dependabot/dependency_file.rb', line 7 def deleted @deleted end |
#directory ⇒ Object
Returns the value of attribute directory.
7 8 9 |
# File 'lib/dependabot/dependency_file.rb', line 7 def directory @directory end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/dependabot/dependency_file.rb', line 7 def name @name end |
#support_file ⇒ Object
Returns the value of attribute support_file.
7 8 9 |
# File 'lib/dependabot/dependency_file.rb', line 7 def support_file @support_file end |
#symlink_target ⇒ Object
Returns the value of attribute symlink_target.
7 8 9 |
# File 'lib/dependabot/dependency_file.rb', line 7 def symlink_target @symlink_target end |
#type ⇒ Object
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
58 59 60 61 62 63 64 |
# File 'lib/dependabot/dependency_file.rb', line 58 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 |
#binary? ⇒ Boolean
82 83 84 |
# File 'lib/dependabot/dependency_file.rb', line 82 def binary? content_encoding == ContentEncoding::BASE64 end |
#decoded_content ⇒ Object
86 87 88 89 90 |
# File 'lib/dependabot/dependency_file.rb', line 86 def decoded_content return Base64.decode64(content) if binary? content end |
#deleted? ⇒ Boolean
78 79 80 |
# File 'lib/dependabot/dependency_file.rb', line 78 def deleted? @deleted end |
#eql?(other) ⇒ Boolean
70 71 72 |
# File 'lib/dependabot/dependency_file.rb', line 70 def eql?(other) self.==(other) end |
#hash ⇒ Object
66 67 68 |
# File 'lib/dependabot/dependency_file.rb', line 66 def hash to_h.hash end |
#path ⇒ Object
54 55 56 |
# File 'lib/dependabot/dependency_file.rb', line 54 def path Pathname.new(File.join(directory, name)).cleanpath.to_path end |
#support_file? ⇒ Boolean
74 75 76 |
# File 'lib/dependabot/dependency_file.rb', line 74 def support_file? @support_file end |
#to_h ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dependabot/dependency_file.rb', line 39 def to_h details = { "name" => name, "content" => content, "directory" => directory, "type" => type, "support_file" => support_file, "content_encoding" => content_encoding, "deleted" => deleted } details["symlink_target"] = symlink_target if symlink_target details end |