Class: Dependabot::DependencyFile
- Inherits:
-
Object
- Object
- Dependabot::DependencyFile
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/dependency_file.rb
Defined Under Namespace
Classes: ContentEncoding, Mode, Operation
Constant Summary collapse
- VALID_MODES =
T.let( [Mode::FILE, Mode::EXECUTABLE, Mode::TREE, Mode::SUBMODULE, Mode::SYMLINK].freeze, T::Array[String] )
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#name ⇒ Object
Returns the value of attribute name.
-
#operation ⇒ Object
Returns the value of attribute operation.
-
#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.
-
#vendored_file ⇒ Object
Returns the value of attribute vendored_file.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #binary? ⇒ Boolean
- #decoded_content ⇒ Object
- #deleted ⇒ Object
- #deleted=(deleted) ⇒ Object
- #deleted? ⇒ Boolean
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name:, content:, directory: "/", type: "file", support_file: false, vendored_file: false, symlink_target: nil, content_encoding: ContentEncoding::UTF_8, deleted: false, operation: Operation::UPDATE, mode: nil) ⇒ DependencyFile
constructor
A new instance of DependencyFile.
- #path ⇒ Object
- #realpath ⇒ Object
- #support_file? ⇒ Boolean
- #to_h ⇒ Object
- #vendored_file? ⇒ Boolean
Constructor Details
#initialize(name:, content:, directory: "/", type: "file", support_file: false, vendored_file: false, symlink_target: nil, content_encoding: ContentEncoding::UTF_8, deleted: false, operation: Operation::UPDATE, mode: nil) ⇒ DependencyFile
Returns a new instance of DependencyFile.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/dependabot/dependency_file.rb', line 84 def initialize( name:, content:, directory: "/", type: "file", support_file: false, vendored_file: false, symlink_target: nil, content_encoding: ContentEncoding::UTF_8, deleted: false, operation: Operation::UPDATE, mode: nil ) @name = name @content = content @directory = T.let(clean_directory(directory), String) @symlink_target = symlink_target @support_file = support_file @vendored_file = vendored_file @content_encoding = content_encoding @operation = operation @mode = mode raise ArgumentError, "Invalid Git mode: #{mode}" if mode && !VALID_MODES.include?(mode) # Make deleted override the operation. Deleted is kept when operation # was introduced to keep compatibility with downstream dependants. @operation = Operation::DELETE if 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.
15 16 17 |
# File 'lib/dependabot/dependency_file.rb', line 15 def content @content end |
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
35 36 37 |
# File 'lib/dependabot/dependency_file.rb', line 35 def content_encoding @content_encoding end |
#directory ⇒ Object
Returns the value of attribute directory.
20 21 22 |
# File 'lib/dependabot/dependency_file.rb', line 20 def directory @directory end |
#mode ⇒ Object
Returns the value of attribute mode.
41 42 43 |
# File 'lib/dependabot/dependency_file.rb', line 41 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/dependabot/dependency_file.rb', line 12 def name @name end |
#operation ⇒ Object
Returns the value of attribute operation.
38 39 40 |
# File 'lib/dependabot/dependency_file.rb', line 38 def operation @operation end |
#support_file ⇒ Object
Returns the value of attribute support_file.
26 27 28 |
# File 'lib/dependabot/dependency_file.rb', line 26 def support_file @support_file end |
#symlink_target ⇒ Object
Returns the value of attribute symlink_target.
32 33 34 |
# File 'lib/dependabot/dependency_file.rb', line 32 def symlink_target @symlink_target end |
#type ⇒ Object
Returns the value of attribute type.
23 24 25 |
# File 'lib/dependabot/dependency_file.rb', line 23 def type @type end |
#vendored_file ⇒ Object
Returns the value of attribute vendored_file.
29 30 31 |
# File 'lib/dependabot/dependency_file.rb', line 29 def vendored_file @vendored_file end |
Instance Method Details
#==(other) ⇒ Object
154 155 156 157 158 159 160 161 162 163 |
# File 'lib/dependabot/dependency_file.rb', line 154 def ==(other) case other when DependencyFile my_hash = to_h.reject { |k| k == "support_file" } their_hash = other.to_h.reject { |k| k == "support_file" } my_hash == their_hash else false end end |
#binary? ⇒ Boolean
201 202 203 |
# File 'lib/dependabot/dependency_file.rb', line 201 def binary? content_encoding == ContentEncoding::BASE64 end |
#decoded_content ⇒ Object
206 207 208 209 210 |
# File 'lib/dependabot/dependency_file.rb', line 206 def decoded_content return Base64.decode64(T.must(content)) if binary? T.must(content) end |
#deleted ⇒ Object
186 187 188 |
# File 'lib/dependabot/dependency_file.rb', line 186 def deleted @operation == Operation::DELETE end |
#deleted=(deleted) ⇒ Object
191 192 193 |
# File 'lib/dependabot/dependency_file.rb', line 191 def deleted=(deleted) @operation = deleted ? Operation::DELETE : Operation::UPDATE end |
#deleted? ⇒ Boolean
196 197 198 |
# File 'lib/dependabot/dependency_file.rb', line 196 def deleted? deleted end |
#eql?(other) ⇒ Boolean
171 172 173 |
# File 'lib/dependabot/dependency_file.rb', line 171 def eql?(other) self == other end |
#hash ⇒ Object
166 167 168 |
# File 'lib/dependabot/dependency_file.rb', line 166 def hash to_h.hash end |
#path ⇒ Object
144 145 146 |
# File 'lib/dependabot/dependency_file.rb', line 144 def path Pathname.new(File.join(directory, name)).cleanpath.to_path end |
#realpath ⇒ Object
149 150 151 |
# File 'lib/dependabot/dependency_file.rb', line 149 def realpath (symlink_target || path).sub(%r{^/}, "") end |
#support_file? ⇒ Boolean
176 177 178 |
# File 'lib/dependabot/dependency_file.rb', line 176 def support_file? @support_file end |
#to_h ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/dependabot/dependency_file.rb', line 126 def to_h details = { "name" => name, "content" => content, "directory" => directory, "type" => type, "support_file" => support_file, "content_encoding" => content_encoding, "deleted" => deleted, "operation" => operation } details["mode"] = mode if mode details["symlink_target"] = symlink_target if symlink_target details end |
#vendored_file? ⇒ Boolean
181 182 183 |
# File 'lib/dependabot/dependency_file.rb', line 181 def vendored_file? @vendored_file end |