module IRB::ExtendCommandBundle

Installs the default irb extensions command bundle.

Constants

NO_OVERRIDE

See ExtendCommandBundle.execute_as_command?.

OVERRIDE_ALL
OVERRIDE_PRIVATE_ONLY

Public Class Methods

all_commands_info() click to toggle source
# File lib/irb/command.rb, line 218
def self.all_commands_info
  return @@commands unless @@commands.empty?
  user_aliases = IRB.CurrentContext.command_aliases.each_with_object({}) do |(alias_name, target), result|
    result[target] ||= []
    result[target] << alias_name
  end

  @EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases|
    if !defined?(Command) || !Command.const_defined?(cmd_class, false)
      require_relative load_file
    end

    klass = Command.const_get(cmd_class, false)
    aliases = aliases.map { |a| a.first }

    if additional_aliases = user_aliases[cmd_name]
      aliases += additional_aliases
    end

    display_name = aliases.shift || cmd_name
    @@commands << { display_name: display_name, description: klass.description, category: klass.category }
  end

  @@commands
end
command_names() click to toggle source
# File lib/irb/command.rb, line 212
def self.command_names
  command_override_policies.keys.map(&:to_s)
end
command_override_policies() click to toggle source
# File lib/irb/command.rb, line 195
def self.command_override_policies
  @@command_override_policies ||= @EXTEND_COMMANDS.flat_map do |cmd_name, cmd_class, load_file, *aliases|
    [[cmd_name, OVERRIDE_ALL]] + aliases
  end.to_h
end
def_extend_command(cmd_name, cmd_class, load_file, *aliases) click to toggle source
# File lib/irb/command.rb, line 258
def self.def_extend_command(cmd_name, cmd_class, load_file, *aliases)
  @EXTEND_COMMANDS.delete_if { |name,| name == cmd_name }
  @EXTEND_COMMANDS << [cmd_name, cmd_class, load_file, *aliases]

  # Just clear memoized values
  @@commands = []
  @@command_override_policies = nil
end
execute_as_command?(name, public_method:, private_method:) click to toggle source
# File lib/irb/command.rb, line 201
def self.execute_as_command?(name, public_method:, private_method:)
  case command_override_policies[name]
  when OVERRIDE_ALL
    true
  when OVERRIDE_PRIVATE_ONLY
    !public_method
  when NO_OVERRIDE
    !public_method && !private_method
  end
end
load_command(command) click to toggle source

Convert a command name to its implementation class if such command exists

# File lib/irb/command.rb, line 245
def self.load_command(command)
  command = command.to_sym
  @EXTEND_COMMANDS.each do |cmd_name, cmd_class, load_file, *aliases|
    next if cmd_name != command && aliases.all? { |alias_name, _| alias_name != command }

    if !defined?(Command) || !Command.const_defined?(cmd_class, false)
      require_relative load_file
    end
    return Command.const_get(cmd_class, false)
  end
  nil
end

Public Instance Methods

irb_load(*opts, &b) click to toggle source

Loads the given file similarly to Kernel#load, see IrbLoader#irb_load

# File lib/irb/ext/use-loader.rb, line 19
def irb_load(*opts, &b)
  Command::Load.execute(irb_context, *opts, &b)
end
irb_require(*opts, &b) click to toggle source

Loads the given file similarly to Kernel#require

# File lib/irb/ext/use-loader.rb, line 24
def irb_require(*opts, &b)
  Command::Require.execute(irb_context, *opts, &b)
end