module Rails::Command::Behavior
def lookup(namespaces)
Receives namespaces in an array and tries to find matching generators
def lookup(namespaces) paths = namespaces_to_paths(namespaces) paths.each do |raw_path| lookup_paths.each do |base| path = "#{base}/#{raw_path}_#{command_type}" begin require path return rescue LoadError => e raise unless /#{Regexp.escape(path)}$/.match?(e.message) rescue Exception => e warn "[WARNING] Could not load #{command_type} #{path.inspect}. Error: #{e.message}.\n#{e.backtrace.join("\n")}" end end end end
def lookup!
def lookup! $LOAD_PATH.each do |base| Dir[File.join(base, *file_lookup_paths)].each do |path| path = path.delete_prefix("#{base}/") require path rescue Exception # No problem end end end
def namespaces_to_paths(namespaces)
an extra lookup. For example, "rails:model" should be searched
Convert namespaces to paths by replacing ":" for "/" and adding
def namespaces_to_paths(namespaces) paths = [] namespaces.each do |namespace| pieces = namespace.split(":") path = pieces.join("/") paths << "#{path}/#{pieces.last}" paths << path end paths.uniq! paths end
def no_color!
def no_color! Thor::Base.shell = Thor::Shell::Basic end
def print_list(base, namespaces)
def print_list(base, namespaces) return if namespaces.empty? puts "#{base.camelize}:" namespaces.each do |namespace| puts(" #{namespace}") end puts end
def subclasses
def subclasses @subclasses ||= [] end