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
|
end
|
||||||
|
|
||||||
protected
|
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)
|
def module_namespacing(&block)
|
||||||
inside_namespace do
|
inside_namespace do
|
||||||
content = capture(&block)
|
content = capture(&block)
|
||||||
if namespaced?
|
content = wrap_with_namespace(content) if namespaced?
|
||||||
content = indent(content)
|
|
||||||
content = wrap_with_namespace(content)
|
|
||||||
end
|
|
||||||
concat(content)
|
concat(content)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,14 +36,16 @@ module Rails
|
||||||
end
|
end
|
||||||
|
|
||||||
def wrap_with_namespace(content)
|
def wrap_with_namespace(content)
|
||||||
|
content = indent(content)
|
||||||
"module #{namespace.name}\n#{content}\nend\n"
|
"module #{namespace.name}\n#{content}\nend\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
def inside_namespace
|
def inside_namespace
|
||||||
@inside_namespace = true if namespaced?
|
@inside_namespace = true if namespaced?
|
||||||
result = yield
|
result = yield
|
||||||
@inside_namespace = false
|
|
||||||
result
|
result
|
||||||
|
ensure
|
||||||
|
@inside_namespace = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def namespace
|
def namespace
|
||||||
|
@ -58,9 +62,6 @@ module Rails
|
||||||
@inside_namespace
|
@inside_namespace
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :file_name
|
|
||||||
alias :singular_name :file_name
|
|
||||||
|
|
||||||
def file_path
|
def file_path
|
||||||
@file_path ||= (class_path + [file_name]).join('/')
|
@file_path ||= (class_path + [file_name]).join('/')
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue