Permalink
Browse files

Refactor a few methods connected with namespacing in Rails::Generator…

…s::NamedBase

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 51c7660 commit 0134c5cc9429abe2427815606088d0084025ba67 @drogus drogus committed with josevalim Sep 25, 2010
Showing with 9 additions and 8 deletions.
  1. +9 −8 railties/lib/rails/generators/named_base.rb
@@ -17,13 +17,15 @@ def initialize(args, *options) #:nodoc:
end
protected
+ attr_reader :file_name
+ alias :singular_name :file_name
+
+ # Wrap block with namespace of current application
+ # if namespace exists and is not skipped
def module_namespacing(&block)
inside_namespace do
content = capture(&block)
- if namespaced?
- content = indent(content)
- content = wrap_with_namespace(content)
- end
+ content = wrap_with_namespace(content) if namespaced?
concat(content)
end
end
@@ -34,14 +36,16 @@ def indent(content, multiplier = 2)
end
def wrap_with_namespace(content)
+ content = indent(content)
"module #{namespace.name}\n#{content}\nend\n"
end
def inside_namespace
@inside_namespace = true if namespaced?
result = yield
- @inside_namespace = false
result
+ ensure
+ @inside_namespace = false
end
def namespace
@@ -58,9 +62,6 @@ def inside_namespace?
@inside_namespace
end
- attr_reader :file_name
- alias :singular_name :file_name
-
def file_path
@file_path ||= (class_path + [file_name]).join('/')
end

0 comments on commit 0134c5c

Please sign in to comment.