Class: Ronin::Repos::Repository Private
- Inherits:
-
Object
- Object
- Ronin::Repos::Repository
- Defined in:
- lib/ronin/repos/repository.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Represents an installed repository.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
private
The name of the repository.
-
#path ⇒ String
readonly
private
The path to the repository's directory.
Class Method Summary collapse
-
.clone(uri, path, depth: nil) ⇒ Repository
private
Clones a repository.
-
.install(uri, path, branch: nil, tag: nil, **kwargs) ⇒ Repository
private
Clones and installs a repository from the URI and to the destination path.
Instance Method Summary collapse
-
#checkout(branch_or_tag) ⇒ true
private
Checks out the git branch or tag.
-
#delete ⇒ Object
private
Deletes the repository directory.
-
#find_file(relative_path) ⇒ String?
private
Finds a file within the repository.
-
#glob(pattern, &block) ⇒ Array<String>
private
Finds all files in the repository that matches the glob pattern.
-
#has_directory?(relative_path) ⇒ Boolean
private
Determines if the repository contains the directory.
-
#has_file?(relative_path) ⇒ Boolean
private
Determines if the repository contains the file.
-
#initialize(path) ⇒ Repository
constructor
private
Initializes the repository.
-
#join(relative_path) ⇒ String
private
Converts a relative path to an absolute path.
-
#list_files(pattern = '{**/}*.*') ⇒ Array<String>
private
Lists the paths within the repository.
-
#pull(remote: 'origin', branch: nil, tags: nil) ⇒ true
private
Pulls down new git commits.
-
#to_s ⇒ String
private
Converts the repository to a String.
-
#update(branch: nil, tag: nil, **kwargs) ⇒ true
private
Updates the repository.
Constructor Details
#initialize(path) ⇒ Repository
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the repository.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ronin/repos/repository.rb', line 51 def initialize(path) @path = File.(path) unless File.exist?(@path) raise(RepositoryNotFound,"repository does not exist: #{@path.inspect}") end unless File.directory?(@path) raise(RepositoryNotFound,"path is not a directory: #{@path.inspect}") end @name = File.basename(@path) end |
Instance Attribute Details
#name ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The name of the repository.
40 41 42 |
# File 'lib/ronin/repos/repository.rb', line 40 def name @name end |
#path ⇒ String (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The path to the repository's directory.
35 36 37 |
# File 'lib/ronin/repos/repository.rb', line 35 def path @path end |
Class Method Details
.clone(uri, path, depth: nil) ⇒ Repository
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Clones a repository.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ronin/repos/repository.rb', line 86 def self.clone(uri,path, depth: nil) path = path.to_s args = [] if depth args << '--depth' << depth.to_s end args << uri.to_s args << path.to_s case system('git','clone',*args) when nil raise(CommandNotInstalled,"git is not installed") when false raise(CommandFailed,"command failed: git clone #{args.join(' ')}") end return new(path) end |
.install(uri, path, branch: nil, tag: nil, **kwargs) ⇒ Repository
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Clones and installs a repository from the URI and to the destination path.
131 132 133 134 135 136 137 138 139 |
# File 'lib/ronin/repos/repository.rb', line 131 def self.install(uri,path, branch: nil, tag: nil, **kwargs) repo = clone(uri,path, **kwargs) if branch || tag repo.checkout(branch || tag) end return repo end |
Instance Method Details
#checkout(branch_or_tag) ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks out the git branch or tag.
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ronin/repos/repository.rb', line 186 def checkout(branch_or_tag) Dir.chdir(@path) do case system('git','checkout',branch_or_tag) when nil raise(CommandNotInstalled,"git is not installed") when false raise(CommandFailed,"command failed: git checkout #{branch_or_tag}") end end end |
#delete ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Deletes the repository directory.
226 227 228 |
# File 'lib/ronin/repos/repository.rb', line 226 def delete FileUtils.rm_rf(@path) end |
#find_file(relative_path) ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds a file within the repository.
283 284 285 286 287 288 289 |
# File 'lib/ronin/repos/repository.rb', line 283 def find_file(relative_path) path = join(relative_path) if File.file?(path) return path end end |
#glob(pattern, &block) ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Finds all files in the repository that matches the glob pattern.
305 306 307 308 309 310 311 312 |
# File 'lib/ronin/repos/repository.rb', line 305 def glob(pattern,&block) path = join(pattern) matches = Dir.glob(path) if block then matches.each(&block) else matches end end |
#has_directory?(relative_path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines if the repository contains the directory.
265 266 267 |
# File 'lib/ronin/repos/repository.rb', line 265 def has_directory?(relative_path) File.directory?(join(relative_path)) end |
#has_file?(relative_path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Determines if the repository contains the file.
252 253 254 |
# File 'lib/ronin/repos/repository.rb', line 252 def has_file?(relative_path) File.file?(join(relative_path)) end |
#join(relative_path) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a relative path to an absolute path.
239 240 241 |
# File 'lib/ronin/repos/repository.rb', line 239 def join(relative_path) File.join(@path,relative_path) end |
#list_files(pattern = '{**/}*.*') ⇒ Array<String>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Lists the paths within the repository.
327 328 329 |
# File 'lib/ronin/repos/repository.rb', line 327 def list_files(pattern='{**/}*.*') Dir.glob(pattern, base: @path) end |
#pull(remote: 'origin', branch: nil, tags: nil) ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Pulls down new git commits.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/ronin/repos/repository.rb', line 158 def pull(remote: 'origin', branch: nil, tags: nil) args = [] args << '--tags' if args << remote.to_s args << branch.to_s if branch Dir.chdir(@path) do case system('git','pull',*args) when nil raise(CommandNotInstalled,"git is not installed") when false raise(CommandFailed,"command failed: git pull #{args.join(' ')}") end end end |
#to_s ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the repository to a String.
337 338 339 |
# File 'lib/ronin/repos/repository.rb', line 337 def to_s @name end |
#update(branch: nil, tag: nil, **kwargs) ⇒ true
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Updates the repository.
215 216 217 218 219 220 221 |
# File 'lib/ronin/repos/repository.rb', line 215 def update(branch: nil, tag: nil, **kwargs) pull(branch: branch, tags: branch.nil?, **kwargs) if branch || tag checkout(branch || tag) end end |