simple_validate 2.0.1 → 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: 215eb056ff7677f32a10c721a53879a52cf3c08f2b8567ba63b86a6aff81d544
4
- data.tar.gz: 4340fa2cfb67c41853f9e5aa4f2d6d1ff8303916d648916bceb799503461dc59
3
+ metadata.gz: 1ac8df574ea6749497a31f423b343ddbb5e7f444a3d5d8ab60d57a3faaa594cf
4
+ data.tar.gz: 0122ded6d697df547de47dc9a47556f8ecffacfe79369675558ad9714c1565fc
5
5
  SHA512:
6
- metadata.gz: a0a854c7b4fd9005eb7e86b035aa585c709d25d33c2b784948ab9d824804c0fdffb04b6e29703bd330f69037d8f9043edf168ca6ede3055a91da5a543ff44db7
7
- data.tar.gz: 67c997ae9cc465d5b54e68b11b5c8438d04cc6b138c981953958c7b8761ba77c472f4a09d9af6a1178ba96271ba2bb8b0bb9cdf81d968b17594f61998a20f68f
6
+ metadata.gz: 8391463f35b4ae5e04c7025941d8a85d0533b69eac371c3b85c8e5e437dd6cdcf7d8c7d7203cc54a8acf00bba2da126a3218fe4eb65642529c2c069fe21254a6
7
+ data.tar.gz: 405ea7f377be0e0f561f8c597dd7c5dc6ac1712663421999014f810a521e85b21224458386154e7e8e9529dc97ba198cd2a463105553ad5e335561bce0a52e35
data/.rspec_status CHANGED
@@ -1,5 +1,8 @@
1
1
  example_id | status | run_time |
2
2
  ------------------------------------- | ------ | --------------- |
3
- ./spec/simple_validate_spec.rb[1:1:1] | passed | 0.00127 seconds |
4
- ./spec/simple_validate_spec.rb[1:2:1] | passed | 0.0001 seconds |
5
- ./spec/simple_validate_spec.rb[1:3:1] | passed | 0.00106 seconds |
3
+ ./spec/simple_validate_spec.rb[1:1:1] | passed | 0.00132 seconds |
4
+ ./spec/simple_validate_spec.rb[1:2:1] | passed | 0.00012 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
+ ./spec/simple_validate_spec.rb[1:5:1] | passed | 0.00006 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
 
@@ -53,7 +53,7 @@ module SimpleValidate
53
53
  raise InvalidLengthOption, "Invalid length option given #{options.keys}"
54
54
  end
55
55
 
56
- actual_length = instance.send(attribute).length
56
+ actual_length = instance.send(attribute)&.length
57
57
  valid_length?(actual_length)
58
58
  end
59
59
  end
@@ -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.1"
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.1
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: