ronin-rb / ronin-core

A core library for all ronin libraries.
https://ronin-rb.dev
GNU Lesser General Public License v3.0
3 stars 3 forks source link

Add a Module Registry API #9

Closed postmodern closed 2 years ago

postmodern commented 2 years ago

Add a "module registry" API that allows Classes to register themselves into a parent Module. It must allow requiring a Class from within a sub-directory (ex: exploits/). The loaded Class would then register itself into the parent Module with a given name. The parent Module would then allow accessing these classes via arbitrary String name.

Pseudo Code

module Ronin
  module Exploits
    include Ronin::Core::Registry.new(dir: `exploits`)
  end

  class Exploit
    def self.register(name)
      Exploits.register(name,self)
    end
  end
end
class SomeExploit < Ronin::Exploits::Exploit

  register 'some_exploit'

  # ...
end
Ronin::Exploits.load('some_exploit')
# => SomeExploit
Ronin::Exploits.registry['some_exploit']
# => SomeExploit

See Also

See Bundler::Audit::CLI::Formats for an example of the Module Registry pattern.