aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/generators/base.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib/rails/generators/base.rb')
-rw-r--r--railties/lib/rails/generators/base.rb27
1 files changed, 13 insertions, 14 deletions
diff --git a/railties/lib/rails/generators/base.rb b/railties/lib/rails/generators/base.rb
index c72ec400a0..1a0420c769 100644
--- a/railties/lib/rails/generators/base.rb
+++ b/railties/lib/rails/generators/base.rb
@@ -1,5 +1,5 @@
begin
- require 'thor/group'
+ require "thor/group"
rescue LoadError
puts "Thor is not available.\nIf you ran this command from a git checkout " \
"of Rails, please make sure thor is installed,\nand run this command " \
@@ -42,13 +42,13 @@ module Rails
# is removed.
def self.namespace(name=nil)
return super if name
- @namespace ||= super.sub(/_generator$/, '').sub(/:generators:/, ':')
+ @namespace ||= super.sub(/_generator$/, "").sub(/:generators:/, ":")
end
# Convenience method to hide this generator from the available ones when
# running rails generator command.
def self.hide!
- Rails::Generators.hide_namespace self.namespace
+ Rails::Generators.hide_namespace(namespace)
end
# Invoke a generator based on the value supplied by the user to the
@@ -168,7 +168,7 @@ module Rails
names.each do |name|
unless class_options.key?(name)
defaults = if options[:type] == :boolean
- { }
+ {}
elsif [true, false].include?(default_value_for_option(name, options))
{ banner: "" }
else
@@ -208,7 +208,7 @@ module Rails
def self.default_source_root
return unless base_name && generator_name
return unless default_generator_root
- path = File.join(default_generator_root, 'templates')
+ path = File.join(default_generator_root, "templates")
path if File.exist?(path)
end
@@ -230,7 +230,7 @@ module Rails
Rails::Generators.subclasses << base
Rails::Generators.templates_path.each do |path|
- if base.name.include?('::')
+ if base.name.include?("::")
base.source_paths << File.join(path, base.base_name, base.generator_name)
else
base.source_paths << File.join(path, base.generator_name)
@@ -251,7 +251,7 @@ module Rails
next if class_name.strip.empty?
# Split the class from its module nesting
- nesting = class_name.split('::')
+ nesting = class_name.split("::")
last_name = nesting.pop
last = extract_last_module(nesting)
@@ -273,13 +273,13 @@ module Rails
# Use Rails default banner.
def self.banner
- "rails generate #{namespace.sub(/^rails:/,'')} #{self.arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, ' ')
+ "rails generate #{namespace.sub(/^rails:/,'')} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ")
end
# Sets the base_name taking into account the current class namespace.
def self.base_name
@base_name ||= begin
- if base = name.to_s.split('::').first
+ if base = name.to_s.split("::").first
base.underscore
end
end
@@ -289,8 +289,8 @@ module Rails
# Rails::Generators::ModelGenerator will return "model" as generator name.
def self.generator_name
@generator_name ||= begin
- if generator = name.to_s.split('::').last
- generator.sub!(/Generator$/, '')
+ if generator = name.to_s.split("::").last
+ generator.sub!(/Generator$/, "")
generator.underscore
end
end
@@ -310,9 +310,9 @@ module Rails
# Returns default for the option name given doing a lookup in config.
def self.default_for_option(config, name, options, default)
- if generator_name and c = config[generator_name.to_sym] and c.key?(name)
+ if generator_name && (c = config[generator_name.to_sym]) && c.key?(name)
c[name]
- elsif base_name and c = config[base_name.to_sym] and c.key?(name)
+ elsif base_name && (c = config[base_name.to_sym]) && c.key?(name)
c[name]
elsif config[:rails].key?(name)
config[:rails][name]
@@ -373,7 +373,6 @@ module Rails
path = File.expand_path(File.join(base_name, generator_name), base_root)
path if File.exist?(path)
end
-
end
end
end