simple_validate 2.0.2 → 2.1.2

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: 633fbb10accca5c33bc717619ef5392f40f53ffea6ccf4dc9e62fa19f934287c
4
- data.tar.gz: 3a93d9d8e9e9fb896dd150f7137893694339c005b87953f5c2c5d6b6e5f03a90
3
+ metadata.gz: 1ac8df574ea6749497a31f423b343ddbb5e7f444a3d5d8ab60d57a3faaa594cf
4
+ data.tar.gz: 0122ded6d697df547de47dc9a47556f8ecffacfe79369675558ad9714c1565fc
5
5
  SHA512:
6
- metadata.gz: '070947710fb4ceecf88974d5126073b8f02b37af1cd185d02e6019281934836655733b6f622bc2ac47f4dba8f5c68eac1c8f8ba4d27f0f31f25d6a01234bc35c'
7
- data.tar.gz: 81ecd04c13e0ef128b16aa7fbce0c845e86dabcc259f9c61f5ad066058359c5a6ca4867360cfa9e65d86ab699975a1554c01fad7ad31970278ca2ea51a7c7285
6
+ metadata.gz: 8391463f35b4ae5e04c7025941d8a85d0533b69eac371c3b85c8e5e437dd6cdcf7d8c7d7203cc54a8acf00bba2da126a3218fe4eb65642529c2c069fe21254a6
7
+ data.tar.gz: 405ea7f377be0e0f561f8c597dd7c5dc6ac1712663421999014f810a521e85b21224458386154e7e8e9529dc97ba198cd2a463105553ad5e335561bce0a52e35
data/.rspec_status CHANGED
@@ -1,8 +1,8 @@
1
1
  example_id | status | run_time |
2
2
  ------------------------------------- | ------ | --------------- |
3
- ./spec/simple_validate_spec.rb[1:1:1] | passed | 0.00127 seconds |
3
+ ./spec/simple_validate_spec.rb[1:1:1] | passed | 0.00132 seconds |
4
4
  ./spec/simple_validate_spec.rb[1:2:1] | passed | 0.00012 seconds |
5
- ./spec/simple_validate_spec.rb[1:3:1] | passed | 0.00104 seconds |
6
- ./spec/simple_validate_spec.rb[1:4:1] | passed | 0.00009 seconds |
5
+ ./spec/simple_validate_spec.rb[1:3:1] | passed | 0.00108 seconds |
6
+ ./spec/simple_validate_spec.rb[1:4:1] | passed | 0.00007 seconds |
7
7
  ./spec/simple_validate_spec.rb[1:5:1] | passed | 0.00006 seconds |
8
- ./spec/simple_validate_spec.rb[1:6:1] | passed | 0.00005 seconds |
8
+ ./spec/simple_validate_spec.rb[1:6:1] | passed | 0.00007 seconds |
data/README.md CHANGED
@@ -18,7 +18,7 @@ class Person
18
18
  attr_accessor :name, :age
19
19
 
20
20
  validates_presence_of :name, :age
21
- validates_numericality_of :age
21
+ validates_type_of :age, as: :integer
22
22
  end
23
23
  ```
24
24
 
@@ -30,7 +30,7 @@ end
30
30
  => p.errors
31
31
  => #<SimpleValidate::Errors:0x007f94318b4df0
32
32
  @messages=
33
- {:age=>["can't be empty", "must be a number"],
33
+ {:age=>["can't be empty", "must be an integer"],
34
34
  :name=>["can't be empty"]}>
35
35
  ```
36
36
 
@@ -2,21 +2,24 @@
2
2
 
3
3
  module SimpleValidate
4
4
  class ValidatesTypeOf < ValidatesBase
5
- SUPPORTED_TYPES = %i[string integer float].freeze
5
+ SUPPORTED_TYPES = %i[string integer float boolean].freeze
6
6
 
7
7
  def initialize(attribute, options)
8
8
  @type = options[:as]
9
9
 
10
10
  raise ArgumentError unless @type && SUPPORTED_TYPES.include?(@type)
11
11
 
12
- @klass = Utils.classify(options[:as])
13
-
14
12
  super(attribute, options[:message] ||
15
13
  "must be #{Utils.article(@type)} #{@type}", options[:if] || proc { true })
16
14
  end
17
15
 
18
16
  def valid?(instance)
19
- instance.send(attribute).is_a?(@klass)
17
+ if @type == :boolean
18
+ [true, false].include? instance.send(attribute)
19
+ else
20
+ klass = Utils.classify(@type)
21
+ instance.send(attribute).is_a?(klass)
22
+ end
20
23
  end
21
24
  end
22
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleValidate
4
- VERSION = "2.0.2"
4
+ VERSION = "2.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_validate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Palaniuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-28 00:00:00.000000000 Z
11
+ date: 2023-08-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: PORO validation mixin with no deps
14
14
  email: