diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2017-07-24 13:39:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-24 13:39:33 -0400 |
commit | 5c418af93770ee33a9e20d0050bd40f26131a410 (patch) | |
tree | 2483bd81c6dad4efb5a17de3c98833abeacc0d3a /railties | |
parent | 6f0729b604dca46d4198f74a08eb836b2e8b5492 (diff) | |
parent | fee24f2189b53c19082770b5b8a62d4a5a0b830c (diff) | |
download | rails-5c418af93770ee33a9e20d0050bd40f26131a410.tar.gz rails-5c418af93770ee33a9e20d0050bd40f26131a410.tar.bz2 rails-5c418af93770ee33a9e20d0050bd40f26131a410.zip |
Merge pull request #29853 from lugray/move_generator_namespacing_to_base
Move generator namespacing to Base
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/base.rb | 37 | ||||
-rw-r--r-- | railties/lib/rails/generators/named_base.rb | 36 |
2 files changed, 37 insertions, 36 deletions
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb index e7f51dba99..9705af8b40 100644 --- a/railties/lib/rails/generators/base.rb +++ b/railties/lib/rails/generators/base.rb @@ -16,6 +16,9 @@ module Rails include Thor::Actions include Rails::Generators::Actions + class_option :skip_namespace, type: :boolean, default: false, + desc: "Skip namespace (affects only isolated applications)" + add_runtime_options! strict_args_position! @@ -271,6 +274,40 @@ module Rails end end + # Wrap block with namespace of current application + # if namespace exists and is not skipped + def module_namespacing(&block) # :doc: + content = capture(&block) + content = wrap_with_namespace(content) if namespaced? + concat(content) + end + + def indent(content, multiplier = 2) # :doc: + spaces = " " * multiplier + content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join + end + + def wrap_with_namespace(content) # :doc: + content = indent(content).chomp + "module #{namespace.name}\n#{content}\nend\n" + end + + def namespace # :doc: + Rails::Generators.namespace + end + + def namespaced? # :doc: + !options[:skip_namespace] && namespace + end + + def namespace_dirs + @namespace_dirs ||= namespace.name.split("::").map(&:underscore) + end + + def namespaced_path # :doc: + @namespaced_path ||= namespace_dirs.join("/") + end + # Use Rails default banner. def self.banner # :doc: "rails generate #{namespace.sub(/^rails:/, '')} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ") diff --git a/railties/lib/rails/generators/named_base.rb b/railties/lib/rails/generators/named_base.rb index d63a5b0c30..dc1d6cab9d 100644 --- a/railties/lib/rails/generators/named_base.rb +++ b/railties/lib/rails/generators/named_base.rb @@ -6,8 +6,6 @@ module Rails module Generators class NamedBase < Base argument :name, type: :string - class_option :skip_namespace, type: :boolean, default: false, - desc: "Skip namespace (affects only isolated applications)" def initialize(args, *options) #:nodoc: @inside_template = nil @@ -45,24 +43,6 @@ module Rails file_name end - # Wrap block with namespace of current application - # if namespace exists and is not skipped - def module_namespacing(&block) # :doc: - content = capture(&block) - content = wrap_with_namespace(content) if namespaced? - concat(content) - end - - def indent(content, multiplier = 2) # :doc: - spaces = " " * multiplier - content.each_line.map { |line| line.blank? ? line : "#{spaces}#{line}" }.join - end - - def wrap_with_namespace(content) # :doc: - content = indent(content).chomp - "module #{namespace.name}\n#{content}\nend\n" - end - def inside_template # :doc: @inside_template = true yield @@ -74,18 +54,6 @@ module Rails @inside_template end - def namespace # :doc: - Rails::Generators.namespace - end - - def namespaced? # :doc: - !options[:skip_namespace] && namespace - end - - def namespace_dirs - @namespace_dirs ||= namespace.name.split("::").map(&:underscore) - end - def file_path # :doc: @file_path ||= (class_path + [file_name]).join("/") end @@ -102,10 +70,6 @@ module Rails @namespaced_class_path ||= namespace_dirs + @class_path end - def namespaced_path # :doc: - @namespaced_path ||= namespace_dirs.join("/") - end - def class_name # :doc: (class_path + [file_name]).map!(&:camelize).join("::") end |