A spec knows where a generator was found and how to instantiate it. Metadata include the generator’s name, its base path, and the source which yielded it (PathSource, GemPathSource, etc.)
# File lib/rubigen/spec.rb, line 23
23: def class_file
24: "#{path}/#{name}_generator.rb"
25: end
# File lib/rubigen/spec.rb, line 27
27: def class_name
28: "#{name.camelize}Generator"
29: end
Look up the generator class. Require its class file, find the class in ObjectSpace, tag it with this spec, and return.
# File lib/rubigen/spec.rb, line 14
14: def klass
15: unless @klass
16: require class_file
17: @klass = lookup_class
18: @klass.spec = self
19: end
20: @klass
21: end
Search for the first Class descending from RubiGen::Base whose name matches the requested class name.
# File lib/rubigen/spec.rb, line 42
42: def lookup_class
43: ObjectSpace.each_object(Class) do |obj|
44: return obj if valid_superclass?(obj) and
45: obj.name.split('::').last == class_name
46: end
47: raise NameError, "Missing #{class_name} class in #{class_file}"
48: end
# File lib/rubigen/spec.rb, line 57
57: def valid_generator_superclasses
58: @valid_generator_superclasses ||= [
59: "RubiGen::Base",
60: "Rails::Generator::Base"
61: ].inject([]) do |list, class_name|
62: klass = class_name.split("::").inject(Object) do |klass, name|
63: klass.const_get(name) rescue nil
64: end
65: list << klass if klass
66: list
67: end
68: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.