aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails')
-rw-r--r--railties/lib/rails/generators/named_base.rb17
1 files changed, 9 insertions, 8 deletions
diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb
index 3632d820ee..9131a19043 100644
--- a/railties/lib/rails/generators/named_base.rb
+++ b/railties/lib/rails/generators/named_base.rb
@@ -17,13 +17,15 @@ module Rails
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 @@ module Rails
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 @@ module Rails
@inside_namespace
end
- attr_reader :file_name
- alias :singular_name :file_name
-
def file_path
@file_path ||= (class_path + [file_name]).join('/')
end