aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2010-09-25 13:41:42 +0200
committerJosé Valim <jose.valim@gmail.com>2010-09-25 17:28:10 +0200
commit0134c5cc9429abe2427815606088d0084025ba67 (patch)
treee863c1e588fe2189c75723b8b61a3e34d45d33d0 /railties/lib/rails
parent51c7660e089017adcf064301188c5b584cb41db0 (diff)
downloadrails-0134c5cc9429abe2427815606088d0084025ba67.tar.gz
rails-0134c5cc9429abe2427815606088d0084025ba67.tar.bz2
rails-0134c5cc9429abe2427815606088d0084025ba67.zip
Refactor a few methods connected with namespacing in Rails::Generators::NamedBase
Signed-off-by: José Valim <jose.valim@gmail.com>
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