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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d2f4e9b0792163ebbdc7214f96347f720aff6b0bbebbc96349714593c8f98ad1
4
- data.tar.gz: 9fbf7f822ea814c20b0d751105a4f4b82a4d975149fe996bc3c66cd56601291b
3
+ metadata.gz: de163a1fc2ca9dd60c4a4fa174cc70e1151aa37f1acdf22ae16e7edfbe975533
4
+ data.tar.gz: 7b537f4c5d60b2824b8a861d36843b228403d5539e4027fc8edbc1048ea25207
5
5
  SHA512:
6
- metadata.gz: 67d3ae16547ba6236d61bca44185b4f47a3243f669d631520805302f1c7dd19037ce8980cc3d40a9e4c0c394f1d71636450f9de74cb5b25bfc81b9cce127d0c3
7
- data.tar.gz: 74a4783cd2df32515651fe938384045de8f77d5f43482d97ef0352f84d0b43a7205cc703835e15c5e85dbfa67da35c7b8c18675fa66d38e67af2594a3b6d4b2e
6
+ metadata.gz: af05f4d2f86e30f8b84544c762171e8467a1a24e26b690084ee19469b1925180410f26f77557a99602ba78965debe385541cb1d716e1f86e1d34213d5af4ffa8
7
+ data.tar.gz: 6db718ef3cc738d354d82246ba0286dd081a8e868e7f46ef5b71943498194188b1563a96a9d5cce2810c99918cad30fe3fd110724d3ec044c091c35e7796185a
data/.travis.yml CHANGED
@@ -6,5 +6,4 @@ rvm:
6
6
  - 2.3.8
7
7
  - 2.4.5
8
8
  - 2.5.3
9
- - rbx-3.107
10
9
  before_install: gem install bundler -v 1.17.2
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
- gem "bundler", "~> 1.17"
6
- gem "rake", "~> 10.0"
7
- gem "rspec", "~> 3.0"
8
- gem "pry", "~> 0.12"
9
- gem "pry-byebug", "~> 3.6"
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 <= Struct
33
- Struct.new(*@kv.keys).new(*@kv.values)
34
- elsif @object_class.respond_to?(:members)
35
- raise "#{ @object_class } struct members don't match" unless (@object_class.members - @kv.keys).empty?
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
@@ -1,3 +1,3 @@
1
1
  class SmartKv
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-22 00:00:00.000000000 Z
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.