| Module | Rails::Generator::Lookup::ClassMethods |
| In: |
vendor/rails/railties/lib/rails_generator/lookup.rb
|
Add a source to the end of the list.
# File vendor/rails/railties/lib/rails_generator/lookup.rb, line 70
70: def append_sources(*args)
71: sources.concat(args.flatten)
72: invalidate_cache!
73: end
Lookup knows how to find generators’ Specs from a list of Sources. Searches the sources, in order, for the first matching name.
# File vendor/rails/railties/lib/rails_generator/lookup.rb, line 124
124: def lookup(generator_name)
125: @found ||= {}
126: generator_name = generator_name.to_s.downcase
127: @found[generator_name] ||= cache.find { |spec| spec.name == generator_name }
128: unless @found[generator_name]
129: chars = generator_name.scan(/./).map{|c|"#{c}.*?"}
130: rx = /^#{chars}$/
131: gns = cache.select{|spec| spec.name =~ rx }
132: @found[generator_name] ||= gns.first if gns.length == 1
133: raise GeneratorError, "Pattern '#{generator_name}' matches more than one generator: #{gns.map{|sp|sp.name}.join(', ')}" if gns.length > 1
134: end
135: @found[generator_name] or raise GeneratorError, "Couldn't find '#{generator_name}' generator"
136: end
Add a source to the beginning of the list.
# File vendor/rails/railties/lib/rails_generator/lookup.rb, line 76
76: def prepend_sources(*args)
77: write_inheritable_array(:sources, args.flatten + sources)
78: invalidate_cache!
79: end
Reset the source list.
# File vendor/rails/railties/lib/rails_generator/lookup.rb, line 82
82: def reset_sources
83: write_inheritable_attribute(:sources, [])
84: invalidate_cache!
85: end
Use application generators (app, ?).
# File vendor/rails/railties/lib/rails_generator/lookup.rb, line 88
88: def use_application_sources!
89: reset_sources
90: sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/applications")
91: end
Use component generators (model, controller, etc).
# File vendor/rails/railties/lib/rails_generator/lookup.rb, line 104
104: def use_component_sources!
105: reset_sources
106: if defined? ::RAILS_ROOT
107: sources << PathSource.new(:lib, "#{::RAILS_ROOT}/lib/generators")
108: sources << PathSource.new(:vendor, "#{::RAILS_ROOT}/vendor/generators")
109: Rails.configuration.plugin_paths.each do |path|
110: relative_path = Pathname.new(File.expand_path(path)).relative_path_from(Pathname.new(::RAILS_ROOT))
111: sources << PathSource.new("plugins (#{relative_path})""plugins (#{relative_path})", "#{path}/**/{,rails_}generators")
112: end
113: end
114: sources << PathSource.new(:user, "#{Dir.user_home}/.rails/generators")
115: if Object.const_defined?(:Gem)
116: sources << GemGeneratorSource.new
117: sources << GemPathSource.new
118: end
119: sources << PathSource.new(:builtin, "#{File.dirname(__FILE__)}/generators/components")
120: end