structish 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/structish/validations.rb +10 -2
- data/lib/structish/version.rb +1 -1
- data/lib/structish_object_extensions.rb +0 -8
- 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: bc6186c9beb8e254ba551d042cec7933ec6c9fe224f6ff57324f5f21d092f6c9
|
4
|
+
data.tar.gz: 7ce960425f5a2eab3c9d97d3655ac2947a0c798930d17056a6152d6d6f04c51b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d94b5ec90702b92533160ad386d17e61ed182c9d8a15b3e7451c498ae6c275b94a5c3ced3673bc66f8f38e55ffbef6ab70619455a7af0bca0f598c2156376967
|
7
|
+
data.tar.gz: f019792b357d80d9ceab344922e609448af82caa2edf3b6bda099924ababe08b972eaa7a42f2a41fa0369c77c45b98c9fbf1b205d825af9d9c3f43a09eaaa9a9
|
@@ -26,7 +26,7 @@ module Structish
|
|
26
26
|
def validate_key_restriction(constructor)
|
27
27
|
if self.class.restrict?
|
28
28
|
allowed_keys = validations.map { |attribute| attribute[:key] }
|
29
|
-
valid = (constructor
|
29
|
+
valid = (keys_for(constructor) - allowed_keys).empty?
|
30
30
|
raise(Structish::ValidationError.new("Keys are restricted to #{allowed_keys.join(", ")}", self.class)) unless valid
|
31
31
|
end
|
32
32
|
end
|
@@ -93,7 +93,7 @@ module Structish
|
|
93
93
|
|
94
94
|
def global_attributes_for(constructor)
|
95
95
|
global_attributes_hash[constructor] = begin
|
96
|
-
constructor_keys = constructor
|
96
|
+
constructor_keys = keys_for(constructor)
|
97
97
|
global_validations.each_with_object([]) do |validation, arr|
|
98
98
|
constructor_keys.each { |key| arr << validation.merge(key: key) }
|
99
99
|
end
|
@@ -168,6 +168,14 @@ module Structish
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
+
def keys_for(constructor)
|
172
|
+
if constructor.class <= ::Array
|
173
|
+
[*0..constructor.size-1]
|
174
|
+
elsif constructor.class <= ::Hash
|
175
|
+
constructor.keys
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
171
179
|
end
|
172
180
|
|
173
181
|
module ClassMethods
|
data/lib/structish/version.rb
CHANGED
@@ -6,14 +6,6 @@ class ::Hash
|
|
6
6
|
end
|
7
7
|
|
8
8
|
class ::Array
|
9
|
-
def values
|
10
|
-
self.to_a
|
11
|
-
end
|
12
|
-
|
13
|
-
def keys
|
14
|
-
[*0..self.size-1]
|
15
|
-
end
|
16
|
-
|
17
9
|
def to_structish(structish_klass)
|
18
10
|
raise(ArgumentError, "Class is not a child of Structish::Array") unless structish_klass < Structish::Array
|
19
11
|
structish_klass.new(self)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: structish
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dylan Blakemore
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|