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 8 def initialize(name, path, source) @name, @path, @source, @klass = name, path, source, nil end
# File lib/rubigen/spec.rb, line 23 def class_file "#{path}/#{name}_generator.rb" end
# File lib/rubigen/spec.rb, line 27 def class_name "#{name.camelize}Generator" 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 def klass unless @klass require class_file @klass = lookup_class @klass.spec = self end @klass end
# File lib/rubigen/spec.rb, line 31 def usage_file "#{path}/USAGE" end
# File lib/rubigen/spec.rb, line 35 def visible? File.exists? usage_file end