Skip to content

Commit

Permalink
Remove fetch override and use original key error
Browse files Browse the repository at this point in the history
  • Loading branch information
styd committed Feb 2, 2019
1 parent d7c54ac commit 0c13202
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 20 deletions.
4 changes: 1 addition & 3 deletions lib/smart_kv.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require_relative "smart_kv/version"
require_relative "smart_kv/register"
require_relative "smart_kv/errors"
require_relative "smart_kv/fetch_override"

class SmartKv
extend Register
using FetchOverride

attr_reader :object_class

Expand All @@ -18,7 +16,7 @@ def initialize(required_keys = [], optional_keys = [], object_class = nil, kv =
hash = kv.to_h
missing_keys = required_keys - hash.keys
unless missing_keys.empty?
raise KeyError, "missing required key(s): #{missing_keys.map{|k| k.to_sym.inspect }.join(', ')} in #{self.class}"
raise ::KeyError, "missing required key(s): #{missing_keys.map{|k| k.to_sym.inspect }.join(', ')} in #{self.class}"
end

unrecognized_keys = hash.keys - required_keys - optional_keys
Expand Down
1 change: 0 additions & 1 deletion lib/smart_kv/errors.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
class SmartKv
InitializationError = Class.new(StandardError)
KeyError = Class.new(StandardError)
end
11 changes: 0 additions & 11 deletions lib/smart_kv/fetch_override.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/smart_kv/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class SmartKv
VERSION = "0.2.0"
VERSION = "0.2.1"
end
8 changes: 4 additions & 4 deletions spec/smart_kv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ModelConfig < described_class
ModelConfig.new({
a_key: "value", and_another: "value again"
})
}.to raise_error(SmartKv::KeyError, /missing required key\(s\): :another_key/)
}.to raise_error(KeyError, /missing required key\(s\): :another_key/)
end

it "doesn't complain when all required keys are there" do
Expand All @@ -52,7 +52,7 @@ class ModelConfig < described_class
a_key: "value", c_key: "value again",
another_key: "wow.. value", and_another: "excellent"
})
}.to raise_error(SmartKv::KeyError, /key not found: :c_key.*Did you mean\?/m)
}.to raise_error(KeyError, /key not found: :c_key.*Did you mean\?/m)
end

it "can access the input value from the object" do
Expand Down Expand Up @@ -225,7 +225,7 @@ class ConvertableConfig
end

it "the instance will be callable as instance of Struct" do
config = ConvertableConfig.new(OstructKv)
config = ConvertableConfig.new(OstructKv)
expect { config.some_key }.not_to raise_error
expect(config.some_key).to eq "value"
expect(config.members).to eq [:some_key]
Expand Down Expand Up @@ -330,7 +330,7 @@ class OptionalToRequired < SmartKv
it "makes the keys no longer required but allowed (optional)" do
expect {
OptionalToRequired.new
}.to raise_error(SmartKv::KeyError, /missing required key\(s\): :b_key/)
}.to raise_error(KeyError, /missing required key\(s\): :b_key/)
expect(OptionalToRequired.optional_keys).to be_empty
expect(OptionalToRequired.required_keys).to eq [:b_key]
end
Expand Down

0 comments on commit 0c13202

Please sign in to comment.