valideizer 1.2.1 → 1.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: af9eb189f03b2ee23f2f688fc05ba140828d27c994b8e09c9ab3c148a2510cce
4
- data.tar.gz: 27197cedb634dcf3a3dcb95599270c7ce7764507f55f147c8ee9921b9fb9d063
3
+ metadata.gz: 6f985b7f1bc2c001c9ef84844ee5d8480f1ca3ca1fe5a802491918cefa69717d
4
+ data.tar.gz: 7a974812bb9e122298afce54bbcbd1d6cfc455502717b7088d1641b98780b68f
5
5
  SHA512:
6
- metadata.gz: 49debeda89e3f5f1a538b0ea67d2b9dfb27a725c67069a012e8e2d1a52d8119cbae42b6bffb776665d029c03c6ca4a5cd58f678175213d767febedf987da0ff9
7
- data.tar.gz: 19b27f84237bf5baae8319d427b686504b7933aa6d76f40f2696f828bc6f6693bb2e1c105916506e0e47a5dd8ba2d4283a1099daed972e1e594cb8f361bc73a0
6
+ metadata.gz: d59b3d7481d93a099975bc62f52c9adda99b969ebdcfee31a07680b79d846ce0fbfd6045124b6626aa24fcf0ade233e124c04385bf67e15ea3e802e9f16d0a77
7
+ data.tar.gz: efb955fdff449a4d6b19697e1a361b6ffa7042b187301f5710ac31e4d175ca1f604781e1f3c53458b65aa9fcce5ec1ed10e92803c35285b8451bd08663715722
@@ -1,4 +1,4 @@
1
- require 'time'
1
+ require 'date'
2
2
 
3
3
  module Valideizer
4
4
  module Caster
@@ -15,11 +15,11 @@ module Valideizer
15
15
  end
16
16
 
17
17
  def cast_to_time(value)
18
- Time.parse(value) rescue nil
18
+ DateTime.parse(value) rescue nil
19
19
  end
20
20
 
21
21
  def cast_to_time_with_format(value, format)
22
- Time.strptime(value, format) rescue nil
22
+ DateTime.strptime(value, format) rescue nil
23
23
  end
24
24
 
25
25
  def cast_to_boolean(value)
@@ -1,5 +1,5 @@
1
1
  require 'json'
2
- require 'time'
2
+ require 'date'
3
3
 
4
4
  module Valideizer
5
5
  module Rules
@@ -21,6 +21,7 @@ module Valideizer
21
21
  when :length then validate_length value, constraint
22
22
  when :active_record then validate_active_record value, constraint
23
23
  when :format then validate_time_format value, constraint
24
+ when :unique then validate_unique value, constraint
24
25
  else true
25
26
  end
26
27
  rescue
@@ -69,7 +70,7 @@ module Valideizer
69
70
 
70
71
  def validate_enum(value, constraint)
71
72
  raise 'Must be an array' unless constraint.is_a? Array
72
- constraint.include? value
73
+ value.is_a?(Array) ? value.all? { |v| constraint.include?(v) } : constraint.include?(value)
73
74
  end
74
75
 
75
76
  def validate_type(value, constraint)
@@ -95,7 +96,7 @@ module Valideizer
95
96
  end
96
97
 
97
98
  def date_time_check(value)
98
- Time.parse(value) rescue return(false)
99
+ DateTime.parse(value) rescue return(false)
99
100
  true
100
101
  end
101
102
 
@@ -178,8 +179,17 @@ module Valideizer
178
179
  end
179
180
 
180
181
  def validate_time_format(value, constraint)
181
- Time.strptime(value, constraint) rescue return(false)
182
+ DateTime.strptime(value, constraint) rescue return(false)
182
183
  true
183
184
  end
185
+
186
+ def validate_unique(value, constraint = true)
187
+ if constraint
188
+ raise "#{value} isn't Array." unless value.is_a?(Array)
189
+ value.count == value.uniq.count
190
+ else
191
+ true
192
+ end
193
+ end
184
194
  end
185
195
  end
@@ -30,7 +30,7 @@ module Valideizer
30
30
  json: %i[null default],
31
31
  boolean: %i[null default],
32
32
  hash: %i[null default length],
33
- array: %i[null default length],
33
+ array: %i[null default length enum uniq],
34
34
  }.freeze
35
35
 
36
36
  def check_rule_set(rules)
@@ -1,3 +1,3 @@
1
1
  module Valideizer
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valideizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arthur 'ArtK0DE' Korochansky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-07 00:00:00.000000000 Z
11
+ date: 2020-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler