ratatouille 1.3.2 → 1.3.4
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.
- data/CHANGELOG.md +11 -0
- data/lib/ratatouille.rb +2 -0
- data/lib/ratatouille/ratifier.rb +16 -2
- data/lib/ratatouille/version.rb +1 -1
- data/spec/lib/ratatouille/ratifier_spec.rb +14 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 1.3.4
|
2
|
+
|
3
|
+
### Updates
|
4
|
+
|
5
|
+
* :is\_a now available as an option in **ratify** to reduce unnecessary nesting
|
6
|
+
|
7
|
+
### Corrections
|
8
|
+
|
9
|
+
* Fixed logic error while processing missing methods. It will correctly call super on missing\_method if
|
10
|
+
we do not catch expected methods
|
11
|
+
|
1
12
|
## 1.3.2
|
2
13
|
|
3
14
|
### Updates
|
data/lib/ratatouille.rb
CHANGED
@@ -11,6 +11,8 @@ module Ratatouille
|
|
11
11
|
|
12
12
|
# @param [Hash, Array] obj Object to validate
|
13
13
|
# @param [Hash] options
|
14
|
+
# @option options [Class] :is_a
|
15
|
+
# @option options [String, Symbol] :name
|
14
16
|
# @return [Validatable::Ratifier]
|
15
17
|
def ratify(obj, options={}, &block)
|
16
18
|
Ratatouille::Ratifier.new(obj, options, &block)
|
data/lib/ratatouille/ratifier.rb
CHANGED
@@ -13,12 +13,18 @@ module Ratatouille
|
|
13
13
|
@ratifiable_object = obj
|
14
14
|
self.name = options[:name]
|
15
15
|
|
16
|
+
@is_a ||= options[:is_a]
|
17
|
+
|
16
18
|
case obj
|
17
19
|
when Hash then extend Ratatouille::HashMethods
|
18
20
|
when Array then extend Ratatouille::ArrayMethods
|
19
21
|
end
|
20
22
|
|
21
|
-
|
23
|
+
unless @is_a.nil?
|
24
|
+
is_a?(@is_a, &block)
|
25
|
+
else
|
26
|
+
instance_eval( &block ) if block_given?
|
27
|
+
end
|
22
28
|
|
23
29
|
cleanup_errors
|
24
30
|
|
@@ -174,16 +180,24 @@ module Ratatouille
|
|
174
180
|
if @ratifiable_object.respond_to?("#{$1}?")
|
175
181
|
if @ratifiable_object.send("#{$1}?") == true
|
176
182
|
validation_error("is #{$1}")
|
183
|
+
return
|
177
184
|
end
|
178
185
|
end
|
179
186
|
when id.to_s =~ /^is_(.*)$/
|
180
187
|
if @ratifiable_object.respond_to?("#{$1}?")
|
181
188
|
if @ratifiable_object.send("#{$1}?") == false
|
182
189
|
validation_error("is not #{$1}")
|
190
|
+
return
|
183
191
|
end
|
184
192
|
end
|
185
193
|
else
|
186
|
-
|
194
|
+
begin
|
195
|
+
super
|
196
|
+
return
|
197
|
+
rescue Exception => e
|
198
|
+
validation_error("#{id} is not supported for the given object (#{@ratifiable_object.class})")
|
199
|
+
return e
|
200
|
+
end
|
187
201
|
end
|
188
202
|
|
189
203
|
instance_eval(&block) if block_given?
|
data/lib/ratatouille/version.rb
CHANGED
@@ -9,6 +9,20 @@ describe Ratatouille::Ratifier do
|
|
9
9
|
e.should be_valid
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should not progress into block if :is_a validation fails" do
|
13
|
+
f = false
|
14
|
+
RatifierTest.new({}, :is_a => String) { f = true }
|
15
|
+
f.should be_false
|
16
|
+
|
17
|
+
g = false
|
18
|
+
RatifierTest.new({}, :is_a => Hash) { g = true }
|
19
|
+
g.should be_true
|
20
|
+
|
21
|
+
h = false
|
22
|
+
RatifierTest.new({}) { h = true }
|
23
|
+
h.should be_true
|
24
|
+
end
|
25
|
+
|
12
26
|
it "errors should contain one key within block of new instance" do
|
13
27
|
x = {}
|
14
28
|
e = RatifierTest.new({}){ x = @errors }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ratatouille
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 1.3.
|
9
|
+
- 4
|
10
|
+
version: 1.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Johnson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-04-
|
18
|
+
date: 2012-04-25 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|