3
# A spec knows where a generator was found and how to instantiate it.
4
# Metadata include the generator's name, its base path, and the source
5
# which yielded it (PathSource, GemPathSource, etc.)
7
attr_reader :name, :path, :source
9
def initialize(name, path, source)
10
@name, @path, @source = name, path, source
13
# Look up the generator class. Require its class file, find the class
14
# in ObjectSpace, tag it with this spec, and return.
25
"#{path}/#{name}_generator.rb"
29
"#{name.camelize}Generator"
33
# Search for the first Class descending from Rails::Generator::Base
34
# whose name matches the requested class name.
36
ObjectSpace.each_object(Class) do |obj|
37
return obj if obj.ancestors.include?(Rails::Generator::Base) and
38
obj.name.split('::').last == class_name
40
raise NameError, "Missing #{class_name} class in #{class_file}"