mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
add ReservedKeyError; reserve more keys.
This commit is contained in:
parent
7035f614e9
commit
c49d031c64
2 changed files with 6 additions and 7 deletions
|
@ -2,6 +2,7 @@ module Pry::Config::Behavior
|
|||
ASSIGNMENT = "=".freeze
|
||||
NODUP = [TrueClass, FalseClass, NilClass, Symbol, Numeric, Module, Proc].freeze
|
||||
INSPECT_REGEXP = /#{Regexp.escape "default=#<"}/
|
||||
ReservedKeyError = Class.new(RuntimeError)
|
||||
|
||||
module Builder
|
||||
def from_hash(hash, default = nil)
|
||||
|
@ -12,15 +13,13 @@ module Pry::Config::Behavior
|
|||
end
|
||||
|
||||
def self.included(klass)
|
||||
unless defined?(RESERVED_KEYS)
|
||||
const_set :RESERVED_KEYS, instance_methods(false).map(&:to_s).freeze
|
||||
end
|
||||
klass.extend(Builder)
|
||||
end
|
||||
|
||||
def initialize(default = Pry.config)
|
||||
@default = default
|
||||
@lookup = {}
|
||||
@reserved_keys = methods.map(&:to_s).freeze
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -38,8 +37,8 @@ module Pry::Config::Behavior
|
|||
|
||||
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."
|
||||
if @reserved_keys.include?(key)
|
||||
raise ReservedKeyError, "few things are reserved by pry, but using '#{key}' as a configuration key is."
|
||||
end
|
||||
__push(key,value)
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ describe Pry::Config do
|
|||
describe "reserved keys" do
|
||||
it "raises an ArgumentError on assignment of a reserved key" do
|
||||
local = Pry::Config.new
|
||||
Pry::Config::RESERVED_KEYS.each do |key|
|
||||
expect { local[key] = 1 }.to raise_error ArgumentError
|
||||
local.instance_variable_get(:@reserved_keys).each do |key|
|
||||
expect { local[key] = 1 }.to raise_error(Pry::Config::ReservedKeyError)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue