Module: PryCommandSetRegistry
- Extended by:
- Forwardable
- Defined in:
- lib/pry_command_set_registry.rb,
lib/pry_command_set_registry/version.rb,
lib/pry_command_set_registry/commands.rb,
lib/pry_command_set_registry/registry.rb,
lib/pry_command_set_registry/command_set.rb
Overview
The namespace and primary access point for addressing the PryCommandSetRegistry plugin. Home to the Registry singleton, the primary store of registered command sets.
Defined Under Namespace
Classes: CommandSet, Registry
Constant Summary collapse
- VERSION =
The version of the PryCommandSetRegistry gem.
"0.1.2".freeze
- Commands =
Default commands for interacting with PryCommandSetRegistry imported into Pry.
CommandSet.new("PryCommandSetRegistry", desc, :group => "Command Set Registry") do command("import-set", "Import a Pry command set") do |command_set_name| raise Pry::CommandError, "Provide a command set name" if command_set_name.nil? begin set = target.eval(command_set_name) unless set.respond_to?(:commands) && set.commands.is_a?(Hash) registered_set = PryCommandSetRegistry.command_set(command_set_name) set = registered_set if registered_set end rescue NameError set = PryCommandSetRegistry.command_set(command_set_name) ::Kernel.raise if set.nil? end _pry_.commands.import(set) end command("list-sets", "List registered command sets") do _pry_.output.puts "Registered Command Sets:" _pry_.output.puts format_command_set_listing(PryCommandSetRegistry.command_sets) end helpers do def format_command_set_listing(command_sets) return "" if command_sets.none? max_len = command_sets.keys.max_by(&:length).length sets = command_sets.map do |set_name, set| " #{set_name.ljust(max_len)} - #{set.description}" end sets.join("\n") end end end
Class Attribute Summary collapse
-
.registry ⇒ PryCommandSetRegistry::Registry
readonly
The registry singleton that stores all defined command sets.
Class Method Summary collapse
-
.command_set(name) ⇒ PryCommandSetRegistry::CommandSet?
Attempts to look up a registered command set with the given name.
-
.command_sets ⇒ Hash{String => PryCommandSetRegistry::CommandSet}
The Hash mapping of all registered command sets.
-
.define_command_set(name, description, options = {}) { ... } ⇒ PryCommandSetRegistry::CommandSet
Helper method for defining a command set and registering it immediately.
Class Attribute Details
.registry ⇒ PryCommandSetRegistry::Registry
The registry singleton that stores all defined command sets.
15 16 17 |
# File 'lib/pry_command_set_registry.rb', line 15 def registry @registry end |
Class Method Details
.command_set(name) ⇒ PryCommandSetRegistry::CommandSet?
Attempts to look up a registered command set with the given name. If the name starts with a colon, the colon is removed prior to lookup.
59 |
# File 'lib/pry_command_set_registry.rb', line 59 def_delegators :registry, :command_set, :command_sets, :define_command_set |
.command_sets ⇒ Hash{String => PryCommandSetRegistry::CommandSet}
The Hash mapping of all registered command sets.
59 |
# File 'lib/pry_command_set_registry.rb', line 59 def_delegators :registry, :command_set, :command_sets, :define_command_set |
.define_command_set(name, description, options = {}) { ... } ⇒ PryCommandSetRegistry::CommandSet
Helper method for defining a command set and registering it immediately. All arguments are passed directly to CommandSet#initialize to instantiate a new command set.
59 |
# File 'lib/pry_command_set_registry.rb', line 59 def_delegators :registry, :command_set, :command_sets, :define_command_set |