validated_object 1.0.0 → 1.1.0

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
  SHA1:
3
- metadata.gz: 917e06893558682ef44f4ae1570d73bb265dc980
4
- data.tar.gz: b622a865760b6b3626ed1f270313ef26686371f6
3
+ metadata.gz: 97d91eb8801c44a0daecab2f6bf5e66c1dc34908
4
+ data.tar.gz: b53ae1848ed9176217969907ff95d4ceb6f0d06b
5
5
  SHA512:
6
- metadata.gz: 95affa10a6d3ee9efc02ced04778a8df4adab2e03a914086afbe79717c679454766be1aae77d2aaa7f7da670b82ed5baf9dc20bf0a0b6c6b0c0527123ab2c732
7
- data.tar.gz: 079acd77f94c7c4664534a489fe5525ad47ab38883e666ea8575065138ce158c6d4b73a42d14b9ed175400e8e8251db2a44ff3b11811fb45229444fe6712d64d
6
+ metadata.gz: 7df6a6cacb4a691183fe606828b572a74e08b139d136e8e6826e5fd2ff3f441443b2f4ef451da96a65040075a46ecfee7e123da9f1ed911308c26b586e0482fe
7
+ data.tar.gz: 86ff719a5c3f23f76f843c049a1071b5ff79e6b20953ca482a3cedf33904adde167553d6efce284e067a0f69bb3841534f1bceb2d29a6bd01ed1dacd77bd8931
@@ -0,0 +1,2 @@
1
+ # 1.1.0
2
+ Introduces the new Boolean pseudo-type.
@@ -42,6 +42,10 @@ module ValidatedObject
42
42
  class Base
43
43
  include ActiveModel::Validations
44
44
 
45
+ # Implements a pseudo-boolean class.
46
+ class Boolean
47
+ end
48
+
45
49
  # Instantiate and validate a new object.
46
50
  #
47
51
  # @yieldparam [ValidatedObject] new_object the yielded new object
@@ -63,22 +67,27 @@ module ValidatedObject
63
67
  end
64
68
 
65
69
  # A custom validator which ensures an object is an instance of a class
66
- # or a subclass.
67
- # It's here as a nested class in {ValidatedObject} for easy
68
- # access by subclasses of {ValidatedObject::Base}.
70
+ # or a subclass. It supports a pseudo-boolean class for convenient
71
+ # validation. (Ruby doesn't have a built-in Boolean.)
69
72
  #
70
73
  # @example Ensure that weight is a number
71
74
  # class Dog < ValidatedObject::Base
72
- # attr_accessor :weight
75
+ # attr_accessor :weight, :neutered
73
76
  # validates :weight, type: Numeric
77
+ # validates :neutered, type: Boolean
74
78
  # end
75
79
  class TypeValidator < ActiveModel::EachValidator
76
80
  # @return [nil]
77
81
  def validate_each(record, attribute, value)
78
- expected = options[:with]
79
- return if value.kind_of?(expected)
82
+ expected_class = options[:with]
83
+
84
+ if expected_class == Boolean
85
+ return if value.is_a?(TrueClass) || value.is_a?(FalseClass)
86
+ else
87
+ return if value.is_a?(expected_class)
88
+ end
80
89
 
81
- msg = options[:message] || "is class #{value.class}, not #{expected}"
90
+ msg = options[:message] || "is class #{value.class}, not #{expected_class}"
82
91
  record.errors.add attribute, msg
83
92
  end
84
93
  end
@@ -1,3 +1,3 @@
1
1
  module ValidatedObject
2
- VERSION = '1.0.0'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validated_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-03-25 00:00:00.000000000 Z
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -77,6 +77,7 @@ files:
77
77
  - ".rspec"
78
78
  - ".travis.yml"
79
79
  - Gemfile
80
+ - HISTORY.md
80
81
  - LICENSE.txt
81
82
  - README.md
82
83
  - Rakefile
@@ -111,4 +112,3 @@ signing_key:
111
112
  specification_version: 4
112
113
  summary: Self-validating plain Ruby objects.
113
114
  test_files: []
114
- has_rdoc: