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

Instance Method Details

#extend(*modules) ⇒ PryCommandSetRegistry::CommandSet #extend { ... } ⇒ PryCommandSetRegistry::CommandSet

Overloads:

  • #extend(*modules) ⇒ PryCommandSetRegistry::CommandSet

    Adds the instance methods from each module given as a parameter to the command set. If both a block and modules are provided an ArgumentError will be raised.

    Parameters:

    • *modules (Module)

      One or more modules to extend the command set with.

    Returns:

    Raises:

    • (ArgumentError)

      if called with modules and block or called with neither modules nor block.

  • #extend { ... } ⇒ PryCommandSetRegistry::CommandSet

    Evaluates the block in the context of the command set instance. If both a block and arguments are provided an ArgumentError will be raised.

    Yields:

    • The given block is evaluated on the command set instance.

    Returns:

    Raises:

    • (ArgumentError)

      if called with modules and block or called with neither modules nor block.



66
67
68
69
70
71
72
73
# File 'lib/pry_command_set_registry/command_set.rb', line 66

def extend(*modules)
  if modules.any?
    return super unless block_given?
    raise ArgumentError, "Cannot call extend with block and modules!"
  end
  instance_eval(&Proc.new)
  self
end