Skip to content

Commit d2302e0

Browse files
authored
Add 'validated' as a synonym for 'validates' and bump version to 2.3.2 (#16)
1 parent ab86ea5 commit d2302e0

File tree

6 files changed

+26
-3
lines changed

6 files changed

+26
-3
lines changed

.rspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
--format documentation
21
--color

HISTORY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
# 2.3.2
2+
- Add 'validated' as a synonym for 'validates' (and in the simplified API), so both can be used interchangeably.
3+
14
# 1.1.0
25
Introduces the new Boolean pseudo-type.

lib/validated_object.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,11 @@ def save_error(record, attribute, value, validation_options)
156156
end
157157
end
158158

159+
# Allow 'validated' as a synonym for 'validates'
160+
def self.validated(*args, **kwargs, &block)
161+
validates(*args, **kwargs, &block)
162+
end
163+
159164
private
160165

161166
sig { params(from_hash: SymbolHash).void }

lib/validated_object/simplified_api.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ def validated_attr(attribute, *options)
1212
attr_reader attribute
1313
validates attribute, *options
1414
end
15+
16+
# Allow 'validated' as a synonym for 'validates'.
17+
def validated(*args, **kwargs, &block)
18+
validates(*args, **kwargs, &block)
19+
end
1520
end
1621

1722
end

lib/validated_object/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# frozen_string_literal: true
33

44
module ValidatedObject
5-
VERSION = '2.3.1'
5+
VERSION = '2.3.2'
66
end

spec/validated_object_spec.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class ImmutableApple < ValidatedObject::Base
5555
}.to raise_error(NoMethodError)
5656
end
5757

58-
58+
5959
context 'TypeValidator' do
6060
it 'verifies a valid type' do
6161
small_apple = Apple.new(diameter: 2.0)
@@ -109,5 +109,16 @@ class Apple4 < ValidatedObject::Base
109109
expect { Apple4.new rotten: 1 }.to raise_error(ArgumentError)
110110
end
111111

112+
113+
it "allows 'validated' as a synonym for 'validates'" do
114+
class SynonymApple < ValidatedObject::Base
115+
attr_accessor :diameter
116+
validated :diameter, type: Float
117+
end
118+
apple = SynonymApple.new(diameter: 1.0)
119+
expect(apple).to be_valid
120+
expect { SynonymApple.new(diameter: 'bad') }.to raise_error(ArgumentError)
121+
end
122+
112123
end
113124
end

0 commit comments

Comments
 (0)