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.
-
#last_updated_at ⇒ Time
private
Determines when the repository was last updated.
-
#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.
-
#url ⇒ String
private
The git URL of 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.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ronin/repos/repository.rb', line 52 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.
41 42 43 |
# File 'lib/ronin/repos/repository.rb', line 41 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.
36 37 38 |
# File 'lib/ronin/repos/repository.rb', line 36 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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/ronin/repos/repository.rb', line 87 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.
132 133 134 135 136 137 138 139 140 |
# File 'lib/ronin/repos/repository.rb', line 132 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.
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/ronin/repos/repository.rb', line 215 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.
255 256 257 |
# File 'lib/ronin/repos/repository.rb', line 255 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.
312 313 314 315 316 317 318 |
# File 'lib/ronin/repos/repository.rb', line 312 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.
334 335 336 337 338 339 340 341 |
# File 'lib/ronin/repos/repository.rb', line 334 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.
294 295 296 |
# File 'lib/ronin/repos/repository.rb', line 294 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.
281 282 283 |
# File 'lib/ronin/repos/repository.rb', line 281 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.
268 269 270 |
# File 'lib/ronin/repos/repository.rb', line 268 def join(relative_path) File.join(@path,relative_path) end |
#last_updated_at ⇒ Time
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 when the repository was last updated.
164 165 166 167 168 |
# File 'lib/ronin/repos/repository.rb', line 164 def last_updated_at Dir.chdir(@path) do Time.parse(`git log --date=iso8601 --pretty="%cd" -1`) end 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.
356 357 358 |
# File 'lib/ronin/repos/repository.rb', line 356 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.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/ronin/repos/repository.rb', line 187 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.
366 367 368 |
# File 'lib/ronin/repos/repository.rb', line 366 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.
244 245 246 247 248 249 250 |
# File 'lib/ronin/repos/repository.rb', line 244 def update(branch: nil, tag: nil, **kwargs) pull(branch: branch, tags: branch.nil?, **kwargs) if branch || tag checkout(branch || tag) end end |
#url ⇒ 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.
The git URL of the repository.
150 151 152 153 154 |
# File 'lib/ronin/repos/repository.rb', line 150 def url Dir.chdir(@path) do `git remote get-url origin`.chomp end end |