mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor a few methods connected with namespacing in Rails::Generators::NamedBase
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
51c7660e08
commit
0134c5cc94
1 changed files with 9 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue