Class: Ronin::Wordlists::CacheDir Private
- Inherits:
-
Object
- Object
- Ronin::Wordlists::CacheDir
- Includes:
- Enumerable
- Defined in:
- lib/ronin/wordlists/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.
Represents the cache directory.
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-wordlists/
directory where all repos are stored. Core::Home.cache_dir('ronin-wordlists')
- WORDLIST_TYPES =
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.
Mapping of wordlist
type:
values and their classes. { git: WordlistRepo, file: WordlistFile }
Instance Attribute Summary collapse
-
#path ⇒ String
readonly
private
The path to the cache directory.
-
#wordlist_dir ⇒ WrodlistDir
readonly
private
The directory containing the downloaded wordlists.
Instance Method Summary collapse
-
#[](name) ⇒ WordlistRepo, WordlistFile
private
Accesses a wordlist file or repository from the cache directory.
-
#download(url) ⇒ WordlistFile, WordlistRepo
private
Downloads a wordlist into the cache directory.
-
#each {|name, wordlist| ... } ⇒ Enumerator
private
Enumerates over every wordlist in the cache directory.
-
#initialize(path = PATH) ⇒ CacheDir
constructor
private
Initializes the repository cache.
-
#list(name = '*') ⇒ Array<String>
private
Lists the wordlists in the cache directory.
-
#open(name) ⇒ Wordlist::File
private
Opens a wordlist from the wordlist directory.
-
#purge ⇒ Object
private
Purge all wordlists from the cache directory.
-
#remove(name) ⇒ Object
private
Deletes a wordlist from the cache directory.
-
#update ⇒ Object
private
Updates the wordlists 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.
60 61 62 63 64 65 66 67 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 60 def initialize(path=PATH) @path = path @manifest_file = File.join(@path,'manifest.yml') @wordlist_dir = WordlistDir.new(File.join(@path,'wordlists')) @manifest = load_manifest 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.
47 48 49 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 47 def path @path end |
#wordlist_dir ⇒ WrodlistDir (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 directory containing the downloaded wordlists.
52 53 54 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 52 def wordlist_dir @wordlist_dir end |
Instance Method Details
#[](name) ⇒ WordlistRepo, WordlistFile
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 wordlist file or repository from the cache directory.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 91 def [](name) unless ( = @manifest[name]) raise(WordlistNotFound,"wordlist not downloaded: #{name.inspect}") end type = .fetch(:type) do raise(InvalidManifestFile,"entry #{name.inspect} is missing a :type attribute") end url = .fetch(:url) do raise(InvalidManifestFile,"entry #{name.inspect} is missing a :url attribute") end filename = .fetch(:filename) do raise(InvalidManifestFile,"entry #{name.inspect} is missing a :filename attribute") end path = File.join(@wordlist_dir.path,filename) wordlist_class = WORDLIST_TYPES.fetch(type) do raise(InvalidManifestFile,"unsupported wordlist type: #{type.inspect}") end return wordlist_class.new(path, url: url) end |
#download(url) ⇒ WordlistFile, WordlistRepo
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.
Downloads a wordlist into the cache directory.
173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 173 def download(url) wordlist = @wordlist_dir.download(url) update_manifest do |manifest| manifest[wordlist.name] = { type: wordlist.type, filename: wordlist.filename, url: wordlist.url.to_s } end return wordlist end |
#each {|name, wordlist| ... } ⇒ 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 over every wordlist in the cache directory.
127 128 129 130 131 132 133 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 127 def each return enum_for unless block_given? @manifest.each_key do |name| yield self[name] end end |
#list(name = '*') ⇒ 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 wordlists in the cache directory.
144 145 146 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 144 def list(name='*') @wordlist_dir.list(name) end |
#open(name) ⇒ Wordlist::File
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.
Opens a wordlist from the wordlist directory.
160 161 162 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 160 def open(name) @wordlist_dir.open(name) 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.
Purge all wordlists from the cache directory.
212 213 214 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 212 def purge FileUtils.rm_rf(@path) 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.
Deletes a wordlist from the cache directory.
200 201 202 203 204 205 206 207 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 200 def remove(name) wordlist = self[name] wordlist.delete update_manifest do |manifest| manifest.delete(name) end 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 the wordlists in the cache directory.
190 191 192 |
# File 'lib/ronin/wordlists/cache_dir.rb', line 190 def update each(&:update) end |