nakajima-fixjour 0.0.7 → 0.0.8
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/lib/fixjour/errors.rb +4 -0
- data/lib/fixjour/verify.rb +9 -5
- metadata +1 -1
data/lib/fixjour/errors.rb
CHANGED
@@ -6,6 +6,10 @@ module Fixjour
|
|
6
6
|
# due to a validates_uniqueness_of validation.
|
7
7
|
class DangerousBuilder < StandardError; end
|
8
8
|
|
9
|
+
# Raised when a builder returns an object that cannot
|
10
|
+
# be saved the database.
|
11
|
+
class UnsavableBuilder < StandardError; end
|
12
|
+
|
9
13
|
# Raised when a builder returns an object of the wrong type
|
10
14
|
class WrongBuilderType < StandardError; end
|
11
15
|
|
data/lib/fixjour/verify.rb
CHANGED
@@ -21,7 +21,11 @@ module Fixjour
|
|
21
21
|
error(klass, WrongBuilderType, "must return an instance of #{klass}")
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
begin
|
25
|
+
result.save!
|
26
|
+
rescue => e
|
27
|
+
error(klass, UnsavableBuilder, "raises #{e.inspect} when saved to the database")
|
28
|
+
end
|
25
29
|
|
26
30
|
unless new_record(klass).valid?
|
27
31
|
msg = ""
|
@@ -33,14 +37,14 @@ module Fixjour
|
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
40
|
+
def new_record(klass)
|
41
|
+
evaluator.send("new_#{name_for(klass)}")
|
42
|
+
end
|
43
|
+
|
36
44
|
private
|
37
45
|
|
38
46
|
def error(klass, exception, msg)
|
39
47
|
raise exception.new("The builder for #{klass} #{msg} ")
|
40
48
|
end
|
41
|
-
|
42
|
-
def new_record(klass)
|
43
|
-
evaluator.send("new_#{name_for(klass)}")
|
44
|
-
end
|
45
49
|
end
|
46
50
|
end
|