class Pry::Config

@api private

Attributes

control_d_handler[R]

Public Class Methods

new() click to toggle source
# File lib/pry/config.rb, line 157
def initialize
  merge!(
    input: MemoizedValue.new { lazy_readline },
    output: $stdout.tap { |out| out.sync = true },
    commands: Pry::Commands,
    prompt_name: 'pry',
    prompt: Pry::Prompt[:default],
    prompt_safe_contexts: [String, Numeric, Symbol, nil, true, false],
    print: Pry::ColorPrinter.method(:default),
    quiet: false,
    exception_handler: Pry::ExceptionHandler.method(:handle_exception),

    unrescued_exceptions: [
      ::SystemExit, ::SignalException, Pry::TooSafeException
    ],

    exception_whitelist: MemoizedValue.new do
      output.puts(
        '[warning] Pry.config.exception_whitelist is deprecated, ' \
        'please use Pry.config.unrescued_exceptions instead.'
      )
      unrescued_exceptions
    end,

    hooks: Pry::Hooks.default,
    pager: true,
    system: Pry::SystemCommandHandler.method(:default),
    color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
    default_window_size: 5,
    editor: Pry::Editor.default,
    rc_file: default_rc_file,
    should_load_rc: true,
    should_load_local_rc: true,
    should_trap_interrupts: Pry::Helpers::Platform.jruby?,
    disable_auto_reload: false,
    command_prefix: '',
    auto_indent: Pry::Helpers::BaseHelpers.use_ansi_codes?,
    correct_indent: true,
    collision_warning: false,
    output_prefix: '=> ',
    requires: [],
    should_load_requires: true,
    should_load_plugins: true,
    windows_console_warning: true,
    control_d_handler: Pry::ControlDHandler.method(:default),
    memory_size: 100,
    extra_sticky_locals: {},
    command_completions: proc { commands.keys },
    file_completions: proc { Dir['.'] },
    ls: OpenStruct.new(Pry::Command::Ls::DEFAULT_OPTIONS),
    completer: Pry::InputCompleter,
    history_save: true,
    history_load: true,
    history_file: Pry::History.default_file,
    history_ignorelist: [],
    history: MemoizedValue.new do
      if defined?(input::HISTORY)
        Pry::History.new(history: input::HISTORY)
      else
        Pry::History.new
      end
    end,
    exec_string: ''
  )

  @custom_attrs = {}
end

Public Instance Methods

[](attr) click to toggle source
# File lib/pry/config.rb, line 238
def [](attr)
  @custom_attrs[attr.to_s].call
end
[]=(attr, value) click to toggle source
# File lib/pry/config.rb, line 234
def []=(attr, value)
  @custom_attrs[attr.to_s] = Config::Value.new(value)
end
control_d_handler=(value) click to toggle source
# File lib/pry/config.rb, line 264
def control_d_handler=(value)
  proxy_proc =
    if value.arity == 2
      Pry::Warning.warn(
        "control_d_handler's arity of 2 parameters was deprecated " \
        '(eval_string, pry_instance). Now it gets passed just 1 ' \
        'parameter (pry_instance)'
      )
      proc do |*args|
        if args.size == 2
          value.call(args.first, args[1])
        else
          value.call(args.first.eval_string, args.first)
        end
      end
    else
      proc do |*args|
        if args.size == 2
          value.call(args[1])
        else
          value.call(args.first)
        end
      end
    end
  @control_d_handler = proxy_proc
end
initialize_dup(other) click to toggle source
Calls superclass method
# File lib/pry/config.rb, line 258
def initialize_dup(other)
  super
  @custom_attrs = @custom_attrs.dup
end
merge(config_hash) click to toggle source
# File lib/pry/config.rb, line 230
def merge(config_hash)
  dup.merge!(config_hash)
end
merge!(config_hash) click to toggle source
# File lib/pry/config.rb, line 225
def merge!(config_hash)
  config_hash.each_pair { |attr, value| __send__("#{attr}=", value) }
  self
end
method_missing(method_name, *args, &_block) click to toggle source

rubocop:disable Style/MethodMissingSuper

# File lib/pry/config.rb, line 243
def method_missing(method_name, *args, &_block)
  name = method_name.to_s

  if name.end_with?('=')
    self[name[0..-2]] = args.first
  elsif @custom_attrs.key?(name)
    self[name]
  end
end
respond_to_missing?(method_name, include_all = false) click to toggle source

rubocop:enable Style/MethodMissingSuper

Calls superclass method
# File lib/pry/config.rb, line 254
def respond_to_missing?(method_name, include_all = false)
  @custom_attrs.key?(method_name.to_s.tr('=', '')) || super
end

Private Instance Methods

default_rc_file() click to toggle source
# File lib/pry/config.rb, line 307
def default_rc_file
  if (pryrc = Pry::Env['PRYRC'])
    pryrc
  elsif (xdg_home = Pry::Env['XDG_CONFIG_HOME'])
    # See XDG Base Directory Specification at
    # https://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
    xdg_home + '/pry/pryrc'
  elsif File.exist?(File.expand_path('~/.pryrc'))
    '~/.pryrc'
  else
    '~/.config/pry/pryrc'
  end
end
lazy_readline() click to toggle source
# File lib/pry/config.rb, line 293
def lazy_readline
  require 'readline'
  ::Readline
rescue LoadError
  output.puts(
    "Sorry, you can't use Pry without Readline or a compatible library. \n" \
    "Possible solutions: \n" \
    " * Rebuild Ruby with Readline support using `--with-readline` \n" \
    " * Use the rb-readline gem, which is a pure-Ruby port of Readline \n" \
    " * Use the pry-coolline gem, a pure-ruby alternative to Readline"
  )
  raise
end