module Pry::Config::Behavior

Constants

ASSIGNMENT
INSPECT_REGEXP
NODUP

Public Class Methods

included(klass) click to toggle source
# File lib/pry/config/behavior.rb, line 14
def self.included(klass)
  unless defined?(RESERVED_KEYS)
    const_set :RESERVED_KEYS, instance_methods(false).map(&:to_s).freeze
  end
  klass.extend(Builder)
end
new(default = Pry.config) click to toggle source
# File lib/pry/config/behavior.rb, line 21
def initialize(default = Pry.config)
  @default = default
  @lookup = {}
end

Public Instance Methods

==(other) click to toggle source
# File lib/pry/config/behavior.rb, line 72
def ==(other)
  @lookup == try_convert_to_hash(other)
end
Also aliased as: eql?
[](key) click to toggle source
# File lib/pry/config/behavior.rb, line 34
def [](key)
  @lookup[key.to_s]
end
[]=(key, value) click to toggle source
# File lib/pry/config/behavior.rb, line 38
def []=(key, value)
  key = key.to_s
  if RESERVED_KEYS.include?(key)
    raise ArgumentError, "few things are reserved by pry, but using '#{key}' as a configuration key is."
  end
  @lookup[key] = value
end
clear() click to toggle source
# File lib/pry/config/behavior.rb, line 86
def clear
  @lookup.clear
  true
end
Also aliased as: refresh
default() click to toggle source

@return [Pry::Config::Behavior]

returns the default used if a matching value for a key isn't found in self
# File lib/pry/config/behavior.rb, line 30
def default
  @default
end
eql?(other) click to toggle source
Alias for: ==
forget(key) click to toggle source
# File lib/pry/config/behavior.rb, line 92
def forget(key)
  @lookup.delete(key.to_s)
end
inspect() click to toggle source
# File lib/pry/config/behavior.rb, line 106
def inspect
  key_str = keys.map { |key| "'#{key}'" }.join(",")
  "#<#{_clip_inspect(self)} local_keys=[#{key_str}] default=#{@default.inspect}>"
end
key?(key) click to toggle source
# File lib/pry/config/behavior.rb, line 81
def key?(key)
  key = key.to_s
  @lookup.key?(key)
end
keys() click to toggle source
# File lib/pry/config/behavior.rb, line 96
def keys
  @lookup.keys
end
merge!(other) click to toggle source
# File lib/pry/config/behavior.rb, line 64
def merge!(other)
  other = try_convert_to_hash(other)
  raise TypeError, "unable to convert argument into a Hash" unless other
  other.each do |key, value|
    self[key] = value
  end
end
method_missing(name, *args, &block) click to toggle source
# File lib/pry/config/behavior.rb, line 46
def method_missing(name, *args, &block)
  key = name.to_s
  if key[-1] == ASSIGNMENT
    short_key = key[0..-2]
    self[short_key] = args[0]
  elsif key?(key)
    self[key]
  elsif @default.respond_to?(name)
    value = @default.public_send(name, *args, &block)
    # FIXME: refactor Pry::Hook so that it stores config on the config object,
    # so that we can use the normal strategy.
    self[key] = value = value.dup if key == 'hooks'
    value
  else
    nil
  end
end
pretty_print(q) click to toggle source
# File lib/pry/config/behavior.rb, line 111
def pretty_print(q)
  q.text inspect[1..-1].gsub(INSPECT_REGEXP, "default=<")
end
refresh() click to toggle source
Alias for: clear
respond_to_missing?(key, include_private=false) click to toggle source
# File lib/pry/config/behavior.rb, line 77
def respond_to_missing?(key, include_private=false)
  key?(key) or @default.respond_to?(key) or super(key, include_private)
end
to_h() click to toggle source
Alias for: to_hash
to_hash() click to toggle source
# File lib/pry/config/behavior.rb, line 100
def to_hash
  @lookup.dup
end
Also aliased as: to_h