fixjour 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/fixjour/redundant_check.rb +8 -3
- metadata +1 -1
@@ -15,17 +15,22 @@ module Fixjour
|
|
15
15
|
end
|
16
16
|
|
17
17
|
module RedundancyChecker
|
18
|
-
BUILDER_METHOD_PATTERN =
|
18
|
+
BUILDER_METHOD_PATTERN = /^(new|create|valid)_(\w+)(_attributes)?$/
|
19
19
|
|
20
20
|
def method_added(sym)
|
21
21
|
name = sym.to_s
|
22
22
|
|
23
|
-
if
|
24
|
-
klass_name = match[2].classify
|
23
|
+
if klass_name = get_klass_name(name)
|
25
24
|
if Fixjour.builder_defined?(klass_name)
|
26
25
|
raise RedundantBuilder.new("You already defined a builder for #{inspect}")
|
27
26
|
end
|
28
27
|
end
|
29
28
|
end
|
29
|
+
|
30
|
+
def get_klass_name(name)
|
31
|
+
if match = name.match(BUILDER_METHOD_PATTERN)
|
32
|
+
match[2].classify.gsub(/Attribute$/, '')
|
33
|
+
end
|
34
|
+
end
|
30
35
|
end
|
31
36
|
end
|