Class: Dependabot::DependencyFile
- Inherits:
-
Object
- Object
- Dependabot::DependencyFile
show all
- Defined in:
- lib/dependabot/dependency_file.rb
Defined Under Namespace
Classes: ContentEncoding, Mode, Operation
Instance Attribute Summary collapse
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.
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/dependabot/dependency_file.rb', line 28
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 = clean_directory(directory)
@symlink_target = symlink_target
@support_file = support_file
@vendored_file = vendored_file
@content_encoding = content_encoding
@operation = operation
@operation = Operation::DELETE if deleted
@type = type
begin
@mode = File.stat(realpath).mode.to_s(8)
rescue StandardError
@mode = mode
end
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.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def content
@content
end
|
#content_encoding ⇒ Object
Returns the value of attribute content_encoding.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def content_encoding
@content_encoding
end
|
#directory ⇒ Object
Returns the value of attribute directory.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def directory
@directory
end
|
#mode ⇒ Object
Returns the value of attribute mode.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def mode
@mode
end
|
#name ⇒ Object
Returns the value of attribute name.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def name
@name
end
|
#operation ⇒ Object
Returns the value of attribute operation.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def operation
@operation
end
|
#support_file ⇒ Object
Returns the value of attribute support_file.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def support_file
@support_file
end
|
#symlink_target ⇒ Object
Returns the value of attribute symlink_target.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def symlink_target
@symlink_target
end
|
#type ⇒ Object
Returns the value of attribute type.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def type
@type
end
|
#vendored_file ⇒ Object
Returns the value of attribute vendored_file.
8
9
10
|
# File 'lib/dependabot/dependency_file.rb', line 8
def vendored_file
@vendored_file
end
|
Instance Method Details
#==(other) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/dependabot/dependency_file.rb', line 89
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
125
126
127
|
# File 'lib/dependabot/dependency_file.rb', line 125
def binary?
content_encoding == ContentEncoding::BASE64
end
|
#decoded_content ⇒ Object
129
130
131
132
133
|
# File 'lib/dependabot/dependency_file.rb', line 129
def decoded_content
return Base64.decode64(content) if binary?
content
end
|
#deleted ⇒ Object
113
114
115
|
# File 'lib/dependabot/dependency_file.rb', line 113
def deleted
@operation == Operation::DELETE
end
|
#deleted=(deleted) ⇒ Object
117
118
119
|
# File 'lib/dependabot/dependency_file.rb', line 117
def deleted=(deleted)
@operation = deleted ? Operation::DELETE : Operation::UPDATE
end
|
#deleted? ⇒ Boolean
121
122
123
|
# File 'lib/dependabot/dependency_file.rb', line 121
def deleted?
deleted
end
|
#eql?(other) ⇒ Boolean
101
102
103
|
# File 'lib/dependabot/dependency_file.rb', line 101
def eql?(other)
self == other
end
|
#hash ⇒ Object
97
98
99
|
# File 'lib/dependabot/dependency_file.rb', line 97
def hash
to_h.hash
end
|
#path ⇒ Object
81
82
83
|
# File 'lib/dependabot/dependency_file.rb', line 81
def path
Pathname.new(File.join(directory, name)).cleanpath.to_path
end
|
#realpath ⇒ Object
85
86
87
|
# File 'lib/dependabot/dependency_file.rb', line 85
def realpath
(symlink_target || path).sub(%r{^/}, "")
end
|
#support_file? ⇒ Boolean
105
106
107
|
# File 'lib/dependabot/dependency_file.rb', line 105
def support_file?
@support_file
end
|
#to_h ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/dependabot/dependency_file.rb', line 64
def to_h
details = {
"name" => name,
"content" => content,
"directory" => directory,
"type" => type,
"support_file" => support_file,
"content_encoding" => content_encoding,
"deleted" => deleted,
"operation" => operation,
"mode" => mode
}
details["symlink_target"] = symlink_target if symlink_target
details
end
|
#vendored_file? ⇒ Boolean
109
110
111
|
# File 'lib/dependabot/dependency_file.rb', line 109
def vendored_file?
@vendored_file
end
|