Class: Rails::Generator::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_generator/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, GemSource, etc.)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path, source) ⇒ Spec

Returns a new instance of Spec.



9
10
11
# File 'lib/rails_generator/spec.rb', line 9

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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/rails_generator/spec.rb', line 7

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/rails_generator/spec.rb', line 7

def path
  @path
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/rails_generator/spec.rb', line 7

def source
  @source
end

Instance Method Details

#class_fileObject



24
25
26
# File 'lib/rails_generator/spec.rb', line 24

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

#class_nameObject



28
29
30
# File 'lib/rails_generator/spec.rb', line 28

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.



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

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