Class: RubiGen::Source

Inherits:
Object show all
Includes:
Enumerable
Defined in:
lib/rubigen/lookup.rb

Overview

Sources enumerate (yield from #each) generator specs which describe where to find and how to create generators. Enumerable is mixed in so, for example, source.collect will retrieve every generator. Sources may be assigned a label to distinguish them.

Direct Known Subclasses

AbstractGemSource, PathSource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label) ⇒ Source

Returns a new instance of Source.



189
190
191
# File 'lib/rubigen/lookup.rb', line 189

def initialize(label)
  @label = label
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



188
189
190
# File 'lib/rubigen/lookup.rb', line 188

def label
  @label
end

Instance Method Details

#eachObject

The each method must be implemented in subclasses. The base implementation raises an error.

Raises:

  • (NotImplementedError)


195
196
197
# File 'lib/rubigen/lookup.rb', line 195

def each
  raise NotImplementedError
end

#names(filter = nil) ⇒ Object

Return a convenient sorted list of all generator names.



200
201
202
203
204
205
206
207
208
# File 'lib/rubigen/lookup.rb', line 200

def names(filter = nil)
  inject([]) do |mem, spec|
    case filter
    when :visible
      mem << spec.name if spec.visible?
    end
    mem
  end.sort
end