From 0134c5cc9429abe2427815606088d0084025ba67 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Sat, 25 Sep 2010 13:41:42 +0200 Subject: Refactor a few methods connected with namespacing in Rails::Generators::NamedBase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- railties/lib/rails/generators/named_base.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'railties/lib/rails/generators') 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 -- cgit v1.2.3