class Geny::Registry
Constants
- ENV_PATH
The load path that is read from ENV vars
- GENY_PATH
The load path for Geny's own generators
- LOAD_PATH
The default load path. By default,
Geny
will search- LOCAL_PATH
The load path for project-local generators
Attributes
load_path[R]
The directories to search for commands in @return [Array<String>]
Public Class Methods
new(load_path: LOAD_PATH)
click to toggle source
Create a new registry @param load_path
[Array<String>]
# File lib/geny/registry.rb, line 25 def initialize(load_path: LOAD_PATH) @load_path = load_path end
Public Instance Methods
find(name)
click to toggle source
Find a command by name @param name [String] name of the command @return [Command,nil]
# File lib/geny/registry.rb, line 51 def find(name) load_path.each do |path| parts = name.split(Command::SEPARATOR) file = File.join(path, *parts, Command::FILENAME) root = File.dirname(file) return build(name, root) if File.exist?(file) end nil end
find!(name)
click to toggle source
Find a command by name or raise an error @param name [String] name of the command @raise [NotFoundError] when the command is not found @return [Command]
# File lib/geny/registry.rb, line 66 def find!(name) find(name) || command_not_found!(name) end
scan()
click to toggle source
Iterate over all load paths and find all commands @return [Array<Command>]
# File lib/geny/registry.rb, line 31 def scan glob = File.join("**", Command::FILENAME) commands = load_path.flat_map do |path| path = Pathname.new(path) path.glob(glob).map do |file| root = file.dirname name = root.relative_path_from(path) name = name.to_s.tr(File::SEPARATOR, Command::SEPARATOR) build(name, root.to_s) end end commands.sort_by(&:name) end
Private Instance Methods
build(name, root)
click to toggle source
# File lib/geny/registry.rb, line 72 def build(name, root) Command.new(name: name, root: root, registry: self) end
command_not_found!(name)
click to toggle source
# File lib/geny/registry.rb, line 76 def command_not_found!(name) raise NotFoundError, "There doesn't appear to be a generator named '#{name}'" end