1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Prefer class << self; def over def self.

This commit is contained in:
Akira Matsuda 2016-12-24 23:58:00 +09:00
parent a4c640ac14
commit f9caa5a6dd

View file

@ -67,7 +67,8 @@ module Rails
}
}
def self.configure!(config) #:nodoc:
class << self
def configure!(config) #:nodoc:
api_only! if config.api_only
no_color! unless config.colorize_logging
aliases.deep_merge! config.aliases
@ -78,15 +79,15 @@ module Rails
hide_namespaces(*config.hidden_namespaces)
end
def self.templates_path #:nodoc:
def templates_path #:nodoc:
@templates_path ||= []
end
def self.aliases #:nodoc:
def aliases #:nodoc:
@aliases ||= DEFAULT_ALIASES.dup
end
def self.options #:nodoc:
def options #:nodoc:
@options ||= DEFAULT_OPTIONS.dup
end
@ -102,7 +103,7 @@ module Rails
# some of them are not available by adding a fallback:
#
# Rails::Generators.fallbacks[:shoulda] = :test_unit
def self.fallbacks
def fallbacks
@fallbacks ||= {}
end
@ -110,7 +111,7 @@ module Rails
# everything that is usually browser related, such as assets and session
# migration generators, and completely disable helpers and assets
# so generators such as scaffold won't create them.
def self.api_only!
def api_only!
hide_namespaces "assets", "helper", "css", "js"
options[:rails].merge!(
@ -126,7 +127,7 @@ module Rails
end
# Remove the color from output.
def self.no_color!
def no_color!
Thor::Base.shell = Thor::Shell::Basic
end
@ -135,7 +136,7 @@ module Rails
# Some are aliased such as "rails:migration" and can be
# invoked with the shorter "migration", others are private to other generators
# such as "css:scaffold".
def self.hidden_namespaces
def hidden_namespaces
@hidden_namespaces ||= begin
orm = options[:rails][:orm]
test = options[:rails][:test_framework]
@ -166,15 +167,13 @@ module Rails
end
end
class << self
def hide_namespaces(*namespaces)
hidden_namespaces.concat(namespaces)
end
alias hide_namespace hide_namespaces
end
# Show help message with available generators.
def self.help(command = "generate")
def help(command = "generate")
puts "Usage: rails #{command} GENERATOR [args] [options]"
puts
puts "General options:"
@ -190,16 +189,16 @@ module Rails
print_generators
end
def self.public_namespaces
def public_namespaces
lookup!
subclasses.map(&:namespace)
end
def self.print_generators
def print_generators
sorted_groups.each { |b, n| print_list(b, n) }
end
def self.sorted_groups
def sorted_groups
namespaces = public_namespaces
namespaces.sort!
@ -232,7 +231,7 @@ module Rails
#
# Notice that "rails:generators:webrat" could be loaded as well, what
# Rails looks for is the first and last parts of the namespace.
def self.find_by_namespace(name, base = nil, context = nil) #:nodoc:
def find_by_namespace(name, base = nil, context = nil) #:nodoc:
lookups = []
lookups << "#{base}:#{name}" if base
lookups << "#{name}:#{context}" if context
@ -260,7 +259,7 @@ module Rails
# Receives a namespace, arguments and the behavior to invoke the generator.
# It's used as the default entry point for generate, destroy and update
# commands.
def self.invoke(namespace, args = ARGV, config = {})
def invoke(namespace, args = ARGV, config = {})
names = namespace.to_s.split(":")
if klass = find_by_namespace(names.pop, names.any? && names.join(":"))
args << "--help" if args.empty? && klass.arguments.any?(&:required?)
@ -275,13 +274,13 @@ module Rails
end
end
def self.print_list(base, namespaces)
def print_list(base, namespaces)
namespaces = namespaces.reject { |n| hidden_namespaces.include?(n) }
super
end
# Try fallbacks for the given base.
def self.invoke_fallbacks_for(name, base) #:nodoc:
def invoke_fallbacks_for(name, base) #:nodoc:
return nil unless base && fallbacks[base.to_sym]
invoked_fallbacks = []
@ -296,16 +295,17 @@ module Rails
nil
end
def self.command_type
def command_type
@command_type ||= "generator"
end
def self.lookup_paths
def lookup_paths
@lookup_paths ||= %w( rails/generators generators )
end
def self.file_lookup_paths
def file_lookup_paths
@file_lookup_paths ||= [ "{#{lookup_paths.join(',')}}", "**", "*_generator.rb" ]
end
end
end
end