Class: RubiGen::Spec

Inherits:
Object show all
Defined in:
lib/rubigen/spec.rb

Overview

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.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path, source) ⇒ Spec

Returns a new instance of Spec.



8
9
10
# File 'lib/rubigen/spec.rb', line 8

def initialize(name, path, source)
  @name, @path, @source, @klass = name, path, source, nil
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rubigen/spec.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/rubigen/spec.rb', line 6

def path
  @path
end

#sourceObject (readonly)

Returns the value of attribute source.



6
7
8
# File 'lib/rubigen/spec.rb', line 6

def source
  @source
end

Instance Method Details

#class_fileObject



23
24
25
# File 'lib/rubigen/spec.rb', line 23

def class_file
  "#{path}/#{name}_generator.rb"
end

#class_nameObject



27
28
29
# File 'lib/rubigen/spec.rb', line 27

def class_name
  "#{name.camelize}Generator"
end

#klassObject

Look up the generator class. Require its class file, find the class in ObjectSpace, tag it with this spec, and return.



14
15
16
17
18
19
20
21
# File 'lib/rubigen/spec.rb', line 14

def klass
  unless @klass
    require class_file
    @klass = lookup_class
    @klass.spec = self
  end
  @klass
end

#usage_fileObject



31
32
33
# File 'lib/rubigen/spec.rb', line 31

def usage_file
  "#{path}/USAGE"
end

#visible?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rubigen/spec.rb', line 35

def visible?
  File.exists? usage_file
end