Module: Ronin::Repos::ClassDir::ClassMethods

Defined in:
lib/ronin/repos/class_dir.rb

Overview

Class-methods.

Instance Method Summary collapse

Instance Method Details

#list_filesArray<String>

List the module names within the class_dir and within #repo_class_dir across all installed repositories.

Returns:

  • (Array<String>)


124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ronin/repos/class_dir.rb', line 124

def list_files
  paths   = Set.new(super)
  pattern = File.join(repo_class_dir,"{**/}*.rb")

  # the String#slice range to remove the repo_class_dir/ and .rb ext
  slice_range = (repo_class_dir.length + 1)...-3

  Repos.list_files(pattern).each do |path|
    # NOTE: String#slice is faster than .delete_prefix + delete.suffix
    paths << path.slice(slice_range)
  end

  return paths.to_a
end

#path_for(name) ⇒ String?

Finds a module within class_dir or within repo_class_dir in one of the installed repositories.

Parameters:

  • name (String)

    The module name to lookup.

Returns:

  • (String, nil)

    The path to the module or nil if the module could not be found in class_dir or any of the installed repositories.



150
151
152
153
# File 'lib/ronin/repos/class_dir.rb', line 150

def path_for(name)
  super(name) ||
    Repos.find_file(File.join(repo_class_dir,"#{name}.rb"))
end

#repo_class_dir(new_dir = nil) ⇒ String

Gets or sets the repository module directory name.

Examples:

repo_class_dir "exploits"

Parameters:

  • new_dir (String, nil) (defaults to: nil)

    The new module directory path.

Returns:

  • (String)

    The repository module directory name.

Raises:

  • (NotImplementedError)

    The repo_class_dir method was not defined in the module.



110
111
112
113
114
115
116
# File 'lib/ronin/repos/class_dir.rb', line 110

def repo_class_dir(new_dir=nil)
  if new_dir
    @repo_class_dir = new_dir
  else
    @repo_class_dir || raise(NotImplementedError,"#{self} did not define a repo_class_dir")
  end
end