fixjour 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fixjour/builders.rb +11 -8
- data/lib/fixjour/verify.rb +1 -1
- metadata +1 -1
data/lib/fixjour/builders.rb
CHANGED
@@ -22,7 +22,7 @@ module Fixjour
|
|
22
22
|
|
23
23
|
# The list of classes that have builders defined.
|
24
24
|
def builders
|
25
|
-
@builders ||=
|
25
|
+
@builders ||= {}
|
26
26
|
end
|
27
27
|
|
28
28
|
# This method should always return a valid instance of
|
@@ -49,7 +49,8 @@ module Fixjour
|
|
49
49
|
module_eval(&block)
|
50
50
|
rescue NameError => e
|
51
51
|
if e.name && evaluator.respond_to?(e.name)
|
52
|
-
raise NonBlockBuilderReference.new
|
52
|
+
raise NonBlockBuilderReference.new \
|
53
|
+
"You must use a builder block in order to reference other Fixjour creation methods."
|
53
54
|
else
|
54
55
|
raise e
|
55
56
|
end
|
@@ -59,14 +60,14 @@ module Fixjour
|
|
59
60
|
# Checks to see whether or not a builder is defined. Duh.
|
60
61
|
def builder_defined?(builder)
|
61
62
|
case builder
|
62
|
-
when Class then builders.map(&:klass).include?(builders)
|
63
|
-
when String then builders.map(&:name).include?(builder)
|
64
|
-
when Symbol then builders.map(&:name).include?(builder.to_s)
|
63
|
+
when Class then builders.values.map(&:klass).include?(builders)
|
64
|
+
when String then builders.values.map(&:name).include?(builder)
|
65
|
+
when Symbol then builders.values.map(&:name).include?(builder.to_s)
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
def remove(
|
69
|
-
builders.delete(Builder.new(
|
69
|
+
def remove(klass)
|
70
|
+
builders.delete(Builder.new(klass).name)
|
70
71
|
end
|
71
72
|
|
72
73
|
private
|
@@ -75,8 +76,10 @@ module Fixjour
|
|
75
76
|
# redundant builders aren't defined, which can lead to confusion
|
76
77
|
# when trying to figure out where objects are being created.
|
77
78
|
def add_builder(builder)
|
78
|
-
|
79
|
+
if builders.has_key?(builder.name) and not Fixjour.allow_redundancy?
|
79
80
|
raise RedundantBuilder.new("You already defined a builder for #{builder.klass.inspect}")
|
81
|
+
else
|
82
|
+
builders[builder.name] = builder
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
data/lib/fixjour/verify.rb
CHANGED