smart_kv 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/Gemfile +13 -5
- data/lib/smart_kv.rb +9 -6
- data/lib/smart_kv/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de163a1fc2ca9dd60c4a4fa174cc70e1151aa37f1acdf22ae16e7edfbe975533
|
4
|
+
data.tar.gz: 7b537f4c5d60b2824b8a861d36843b228403d5539e4027fc8edbc1048ea25207
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af05f4d2f86e30f8b84544c762171e8467a1a24e26b690084ee19469b1925180410f26f77557a99602ba78965debe385541cb1d716e1f86e1d34213d5af4ffa8
|
7
|
+
data.tar.gz: 6db718ef3cc738d354d82246ba0286dd081a8e868e7f46ef5b71943498194188b1563a96a9d5cce2810c99918cad30fe3fd110724d3ec044c091c35e7796185a
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -2,8 +2,16 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
4
4
|
|
5
|
-
|
6
|
-
gem "
|
7
|
-
gem "
|
8
|
-
|
9
|
-
|
5
|
+
group :development, :test do
|
6
|
+
gem "pry", "~> 0.12"
|
7
|
+
gem "pry-byebug", "~> 3.6"
|
8
|
+
end
|
9
|
+
|
10
|
+
group :test do
|
11
|
+
gem "rspec", "~> 3.0"
|
12
|
+
end
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem "bundler", "~> 1.17"
|
16
|
+
gem "rake", "~> 10.0"
|
17
|
+
end
|
data/lib/smart_kv.rb
CHANGED
@@ -15,8 +15,12 @@ class SmartKv
|
|
15
15
|
|
16
16
|
@object_class = object_class || kv.class
|
17
17
|
@kv = kv.dup
|
18
|
-
hash = kv.to_h.dup
|
19
18
|
|
19
|
+
if @object_class.respond_to?(:members) && @object_class.members != @kv.to_h.keys
|
20
|
+
raise ArgumentError, "#{ @object_class } struct size differs"
|
21
|
+
end
|
22
|
+
|
23
|
+
hash = kv.to_h.dup
|
20
24
|
missing_keys = required_keys - hash.keys
|
21
25
|
unless missing_keys.empty?
|
22
26
|
raise KeyError, "missing required key(s): #{missing_keys.map{|k| "`:#{k}'" }.join(', ')} in #{self.class}"
|
@@ -29,11 +33,10 @@ class SmartKv
|
|
29
33
|
end
|
30
34
|
|
31
35
|
def method_missing(m, *args)
|
32
|
-
@object ||= if @object_class
|
33
|
-
Struct.new(*@kv.keys).new(*@kv.values)
|
34
|
-
elsif @object_class
|
35
|
-
|
36
|
-
@object_class.new(*@kv.values)
|
36
|
+
@object ||= if @object_class == Struct
|
37
|
+
Struct.new(*@kv.to_h.keys).new(*@kv.to_h.values)
|
38
|
+
elsif @object_class < Struct
|
39
|
+
@object_class.new(*@kv.to_h.values)
|
37
40
|
elsif @object_class <= Hash
|
38
41
|
@kv
|
39
42
|
else
|
data/lib/smart_kv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_kv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrian Setyadi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Best practice of writing configurations by strictly allowing and requiring
|
14
14
|
keys.
|