class Pry::Config

@api private

Attributes

control_d_handler[R]

Public Class Methods

new() click to toggle source
# File lib/pry/config.rb, line 151
def initialize
  merge!(
    input: MemoizedValue.new { choose_input },
    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
    ],

    hooks: Pry::Hooks.default,
    pager: true,
    system: Pry::SystemCommandHandler.method(:default),
    multiline: true,
    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,
    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: Pry::Command::Ls::Config.default,
    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 224
def [](attr)
  @custom_attrs[attr.to_s].call
end
[]=(attr, value) click to toggle source
# File lib/pry/config.rb, line 220
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 250
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 244
def initialize_dup(other)
  super
  @custom_attrs = @custom_attrs.dup
end
merge(config_hash) click to toggle source
# File lib/pry/config.rb, line 216
def merge(config_hash)
  dup.merge!(config_hash)
end
merge!(config_hash) click to toggle source
# File lib/pry/config.rb, line 211
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 229
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 240
def respond_to_missing?(method_name, include_all = false)
  @custom_attrs.key?(method_name.to_s.tr('=', '')) || super
end

Private Instance Methods

choose_input() click to toggle source
# File lib/pry/config.rb, line 279
def choose_input
  input = load_readline

  if Pry::Env['TERM'] == 'dumb' && (defined?(Reline) && input == Reline)
    input = Pry::Input::SimpleStdio
  end

  input
end
default_rc_file() click to toggle source
# File lib/pry/config.rb, line 303
def default_rc_file
  [Pry::Env['PRYRC'],
   # See XDG Base Directory Specification at
   # https://specifications.freedesktop.org/basedir-spec/latest/
   "#{Pry::Env['XDG_CONFIG_HOME']}/pry/pryrc",
   File.expand_path('~/.pryrc'),
   File.expand_path('~/.config/pry/pryrc')]
    .compact
    .find { |file| File.exist?(file) }
end
load_readline() click to toggle source
# File lib/pry/config.rb, line 289
def load_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