watir_model 0.4.6 → 0.5.0

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
  SHA1:
3
- metadata.gz: 0fdf8505d77d7adfa4b9ede2a6c7c6cc65b83bfe
4
- data.tar.gz: a9417429d02f0cfa2685cce6c1f7e7caaf4b158f
3
+ metadata.gz: d4a63d0d44bca88f86db3a5f5a379eacb7e7c1d1
4
+ data.tar.gz: dfa9f23bfaadb59ed9e24191c6ae4d17fb3b854b
5
5
  SHA512:
6
- metadata.gz: e7905f553d635cbeae6ac9b3c917dbbc057d180554700086ece5ea6cc5de8dad5ec019b0c06eb2f9a11ae197a702ed8997f601568b0eef21a4d17c3d61b6ee1e
7
- data.tar.gz: 86da4a818ee420d29891844f679a78c639d117ad7c8007fbffbd7f1d099c33755b9274ed425a2227af00b71563c0e413fec8fd8a814a38337bd019116891daa1
6
+ metadata.gz: 7981185908b815a682f83c7cd33745732aa512fa3681f6561da8ad9aea7d244a9b3d23ecb05a4e6776a3534a2619bc293d9cb4da91a11dc1d9135a0bb4f9f097
7
+ data.tar.gz: dec2feaa6de866aaa79cc1add9b0e1740e0041a831f1184ac51c092fc58fbb06eea1a6d678bc8a45afc11c84873dbad6c4da9c87c309f675337d5d3233e3a928
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 0.5.0 (2017-12-29)
2
+
3
+ * prevent `#convert` when default values won't be used
4
+
1
5
  ### 0.4.6 (2017-12-29)
2
6
 
3
7
  * support for `#to_json`
@@ -30,6 +30,10 @@ class WatirModel
30
30
  @defaults ||= {}
31
31
  end
32
32
 
33
+ def valid_keys
34
+ keys + aliases.keys + apis.keys
35
+ end
36
+
33
37
  def inherited(subclass)
34
38
  subclass.keys = keys.dup
35
39
  subclass.aliases = aliases.dup
@@ -82,7 +86,10 @@ class WatirModel
82
86
 
83
87
  def convert(hash, *args)
84
88
  hash.deep_symbolize_keys!
85
- filtered = hash.select { |k| (keys + aliases.keys + apis.keys).include?(k) }
89
+ filtered = hash.select { |k| valid_keys.include?(k) }
90
+ unless (defaults.keys - default_value_keys(filtered)).empty?
91
+ raise StandardError, "Can not convert Hash to Model when keys with default values are missing"
92
+ end
86
93
  model = new(filtered)
87
94
  args.each do |key|
88
95
  model.instance_eval do
@@ -96,6 +103,12 @@ class WatirModel
96
103
  'config/data'
97
104
  end
98
105
 
106
+ def default_value_keys(hash)
107
+ hash.keys.map do |key|
108
+ keys.include?(key) ? key : (aliases[key] || apis[key])
109
+ end
110
+ end
111
+
99
112
  def method_missing(method, *args, &block)
100
113
  file = factory_file(self)
101
114
  return super unless file
@@ -114,7 +127,7 @@ class WatirModel
114
127
  end
115
128
  end
116
129
 
117
- def initialize(hash={})
130
+ def initialize(hash = {})
118
131
  hash.deep_symbolize_keys!
119
132
  update(hash)
120
133
 
@@ -158,6 +171,10 @@ class WatirModel
158
171
  self.class.apis
159
172
  end
160
173
 
174
+ def valid_keys
175
+ self.class.apis
176
+ end
177
+
161
178
  def [] key
162
179
  send key
163
180
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "watir_model"
5
- spec.version = "0.4.6"
5
+ spec.version = "0.5.0"
6
6
  spec.authors = ["Titus Fortner"]
7
7
  spec.email = ["titusfortner@gmail.com"]
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-29 00:00:00.000000000 Z
11
+ date: 2017-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport