Class: Ronin::Repos::CacheDir Private
- Inherits:
-
Object
- Object
- Ronin::Repos::CacheDir
- Includes:
- Enumerable
- Defined in:
- lib/ronin/repos/cache_dir.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.
Manages the ~/.cache/ronin-repos/
directory and the repositories
contained within.
Constant Summary collapse
- PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The
~/.cache/ronin-repos/
directory where all repos are stored. Core::Home.cache_dir('ronin-repos')
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
private
The path to the cache directory.
Instance Method Summary collapse
-
#[](name) ⇒ Repository
private
Accesses a repository from the cache directory.
-
#each {|repo| ... } ⇒ Enumerator
private
Enumerates through every repository in the cache directory.
-
#find_file(path) ⇒ String?
private
Finds the first matching file.
-
#glob(pattern, &block) ⇒ Array<String>
private
Finds all files in all repos that matches the glob pattern.
-
#initialize(path = PATH) ⇒ CacheDir
constructor
private
Initializes the repository cache.
-
#install(uri, name = nil) ⇒ Repository
private
Clones and installs a repository into the cache directory.
-
#list_files(pattern = '{**/}*.*') ⇒ Set<String>
private
Lists all files across all repos installed in the cache directory.
-
#purge ⇒ Object
private
Deletes all repositories in the cache directory.
-
#remove(name) ⇒ Object
private
Removes a repository from the cache directory.
-
#to_s ⇒ String
private
Converts the cache directory to a String.
-
#update ⇒ Object
private
Updates all repositories in the cache directory.
Constructor Details
#initialize(path = PATH) ⇒ CacheDir
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 cache.
51 52 53 |
# File 'lib/ronin/repos/cache_dir.rb', line 51 def initialize(path=PATH) @path = path end |
Instance Attribute Details
#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 cache directory.
43 44 45 |
# File 'lib/ronin/repos/cache_dir.rb', line 43 def path @path end |
Instance Method Details
#[](name) ⇒ 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.
Accesses a repository from the cache directory.
67 68 69 70 71 72 73 74 75 |
# File 'lib/ronin/repos/cache_dir.rb', line 67 def [](name) path = File.join(@path,name.to_s) unless File.directory?(path) raise(RepositoryNotFound,"repository not found: #{name.inspect}") end return Repository.new(path) end |
#each {|repo| ... } ⇒ Enumerator
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.
Enumerates through every repository in the cache directory.
89 90 91 92 93 94 95 |
# File 'lib/ronin/repos/cache_dir.rb', line 89 def each return enum_for unless block_given? each_child_directory do |path| yield Repository.new(path) end end |
#find_file(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 the first matching file.
173 174 175 176 177 178 179 |
# File 'lib/ronin/repos/cache_dir.rb', line 173 def find_file(path) each do |repo| if (file = repo.find_file(path)) return file end 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 all repos that matches the glob pattern.
197 198 199 200 201 202 203 |
# File 'lib/ronin/repos/cache_dir.rb', line 197 def glob(pattern,&block) return enum_for(__method__,pattern).to_a unless block_given? each do |repo| repo.glob(pattern,&block) end end |
#install(uri, name = 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 and installs a repository into the cache directory.
116 117 118 119 120 121 122 |
# File 'lib/ronin/repos/cache_dir.rb', line 116 def install(uri,name=nil) uri = uri.to_s name ||= File.basename(uri,File.extname(uri)) path = File.join(@path,name) return Repository.install(uri,path) end |
#list_files(pattern = '{**/}*.*') ⇒ Set<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 all files across all repos installed in the cache directory.
218 219 220 221 222 |
# File 'lib/ronin/repos/cache_dir.rb', line 218 def list_files(pattern='{**/}*.*') each_with_object(Set.new) do |repo,files| files.merge(repo.list_files(pattern)) end end |
#purge ⇒ 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 all repositories in the cache directory.
155 156 157 |
# File 'lib/ronin/repos/cache_dir.rb', line 155 def purge each(&:delete) end |
#remove(name) ⇒ 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.
Removes a repository from the cache directory.
148 149 150 |
# File 'lib/ronin/repos/cache_dir.rb', line 148 def remove(name) self[name].delete 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 cache directory to a String.
230 231 232 |
# File 'lib/ronin/repos/cache_dir.rb', line 230 def to_s @path end |
#update ⇒ 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.
Updates all repositories in the cache directory.
130 131 132 133 134 135 136 |
# File 'lib/ronin/repos/cache_dir.rb', line 130 def update each do |repo| repo.update rescue CommandFailed # ignore any `git` errors when updating end end |