Class: PryCommandSetRegistry::CommandSet

Inherits:
Pry::CommandSet
  • Object
show all
Defined in:
lib/pry_command_set_registry/command_set.rb

Overview

A set of commands that can me imported into a Pry session.

Constant Summary collapse

DEFAULT_GROUP_NAME =

The default group name that Pry gives to commands without a group.

"(other)".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, description, options = {}) { ... } ⇒ PryCommandSetRegistry::CommandSet

Creates a new command set.

Examples:

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

CommandSet.new("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.

Raises:

  • (ArgumentError)

    if no block is given.



39
40
41
42
43
44
45
46
# File 'lib/pry_command_set_registry/command_set.rb', line 39

def initialize(name, description, options = {}, &block)
  raise ArgumentError, "Block required!" unless block_given?
  super(&block)
  @description = description
  @name = name.to_s
  @group = options[:group] || DEFAULT_GROUP_NAME
  apply_group_name_to_commands
end

Instance Attribute Details

#descriptionObject (readonly)

The description of the command set provided at creation.



8
9
10
# File 'lib/pry_command_set_registry/command_set.rb', line 8

def description
  @description
end

#groupObject (readonly)

The group name given to the command set at creation.



11
12
13
# File 'lib/pry_command_set_registry/command_set.rb', line 11

def group
  @group
end

#nameObject (readonly)

The name of the command set provided at creation.



14
15
16
# File 'lib/pry_command_set_registry/command_set.rb', line 14

def name
  @name
end