class Dependabot::DependencyFile
Attributes
content[RW]
content_encoding[RW]
directory[RW]
name[RW]
operation[RW]
support_file[RW]
symlink_target[RW]
type[RW]
Public Class Methods
new(name:, content:, directory: "/", type: "file", support_file: false, symlink_target: nil, content_encoding: ContentEncoding::UTF_8, deleted: false, operation: Operation::UPDATE)
click to toggle source
# File lib/dependabot/dependency_file.rb, line 21 def initialize(name:, content:, directory: "/", type: "file", support_file: false, symlink_target: nil, content_encoding: ContentEncoding::UTF_8, deleted: false, operation: Operation::UPDATE) @name = name @content = content @directory = clean_directory(directory) @symlink_target = symlink_target @support_file = support_file @content_encoding = content_encoding @operation = operation # 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
Public Instance Methods
==(other)
click to toggle source
# File lib/dependabot/dependency_file.rb, line 69 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?()
click to toggle source
# File lib/dependabot/dependency_file.rb, line 101 def binary? content_encoding == ContentEncoding::BASE64 end
decoded_content()
click to toggle source
# File lib/dependabot/dependency_file.rb, line 105 def decoded_content return Base64.decode64(content) if binary? content end
deleted()
click to toggle source
# File lib/dependabot/dependency_file.rb, line 89 def deleted @operation == Operation::DELETE end
deleted=(deleted)
click to toggle source
# File lib/dependabot/dependency_file.rb, line 93 def deleted=(deleted) @operation = deleted ? Operation::DELETE : Operation::UPDATE end
deleted?()
click to toggle source
# File lib/dependabot/dependency_file.rb, line 97 def deleted? deleted end
eql?(other)
click to toggle source
# File lib/dependabot/dependency_file.rb, line 81 def eql?(other) self.==(other) end
hash()
click to toggle source
# File lib/dependabot/dependency_file.rb, line 77 def hash to_h.hash end
path()
click to toggle source
# File lib/dependabot/dependency_file.rb, line 65 def path Pathname.new(File.join(directory, name)).cleanpath.to_path end
support_file?()
click to toggle source
# File lib/dependabot/dependency_file.rb, line 85 def support_file? @support_file end
to_h()
click to toggle source
# File lib/dependabot/dependency_file.rb, line 49 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["symlink_target"] = symlink_target if symlink_target details end
Private Instance Methods
clean_directory(directory)
click to toggle source
# File lib/dependabot/dependency_file.rb, line 113 def clean_directory(directory) # Directory should always start with a `/` directory.sub(%r{^/*}, "/") end