Class: PryCommandSetRegistry::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/pry_command_set_registry/registry.rb

Overview

A registry of command sets and descriptions of those command sets.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePryCommandSetRegistry::Registry

Creates a new command set registry.



10
11
12
# File 'lib/pry_command_set_registry/registry.rb', line 10

def initialize
  @command_sets = {}
end

Instance Attribute Details

#command_setsHash{String => PryCommandSetRegistry::CommandSet} (readonly)

The Hash mapping of all registered command sets.

Returns:



6
7
8
# File 'lib/pry_command_set_registry/registry.rb', line 6

def command_sets
  @command_sets
end

Instance 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.

Parameters:

  • name (String, Symbol)

    The name of a registered command set to attempt to retrieve.

Returns:



22
23
24
25
# File 'lib/pry_command_set_registry/registry.rb', line 22

def command_set(name)
  sanitized_name = name.to_s.sub(/^:/, "")
  command_sets[sanitized_name]
end

#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.

Examples:

Create a new CommandSet with a ‘hello-world` command

Registry.define_command_set("Examples", "Example Commands", :group => "Examples") do
  command("hello-world", "Greets the world") do
    _pry_.outputter.puts("Hello world!")
  end
end

Parameters:

  • name (String, Symbol)

    The name that should be given to the command set. The provided name will be displayed by the ‘list-sets` command and is used to identify the command set when calling the `import-set` command.

  • description (String)

    A description of the command set. The provided description will be displayed by the ‘list-sets` command.

  • options (Hash{Symbol=>String}) (defaults to: {})

    Optional arguments.

Options Hash (options):

  • group (String)

    A group name to apply to all commands in the command set. This group will be displayed in commands like ‘help`, however depending on the version of pry it may be sentence cased when displayed. When no group is provided, Pry will use `(other)` by default.

Yields:

  • The provided block is evaluated by the command set instance and is used to define commands and configure the command set in other ways.

Returns:

Raises:

  • (ArgumentError)

    if no block is given.

See Also:



54
55
56
57
58
# File 'lib/pry_command_set_registry/registry.rb', line 54

def define_command_set(name, description, options = {}, &block)
  command_set = CommandSet.new(name, description, options, &block)
  command_sets[command_set.name] = command_set
  command_set
end