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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb8375ce872710c3e8110f8a828634a250eb511edb287cec4727bd164b5e6603
4
- data.tar.gz: 188c37b662cb237aae784d8c1e13092d704db44ce919e3db39134164de7bb8f5
3
+ metadata.gz: bc6186c9beb8e254ba551d042cec7933ec6c9fe224f6ff57324f5f21d092f6c9
4
+ data.tar.gz: 7ce960425f5a2eab3c9d97d3655ac2947a0c798930d17056a6152d6d6f04c51b
5
5
  SHA512:
6
- metadata.gz: 86939b735cdb7ccb5d5b23235591bcd5fb9489605e642484775a516fad253fc5d24bca7ddf3c94221bc59954d4fb32fe3a579de704a4546f105162eb1f9e6749
7
- data.tar.gz: c50734865d6eef701c9cda85e765c715dbdf90d0c69764800162cf5b445812e7d4222c5a1ed28eabbabc8d740aa1d3a45ae9c900e7646b68a1136fcf2c58c15f
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.keys - allowed_keys).empty?
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.keys
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
@@ -1,3 +1,3 @@
1
1
  module Structish
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -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.1
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-01 00:00:00.000000000 Z
11
+ date: 2021-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport