Class: Butterfly::CodeGenerators
- Inherits:
-
Object
- Object
- Butterfly::CodeGenerators
- Defined in:
- lib/butterfly.rb
Overview
Generator
Defined Under Namespace
Classes: GeneratorGroup
Instance Attribute Summary collapse
-
#generators ⇒ Object
Returns the value of attribute generators.
Instance Method Summary collapse
-
#initialize ⇒ CodeGenerators
constructor
A new instance of CodeGenerators.
-
#names ⇒ Object
returns array of generator-group names.
-
#source_of(name) ⇒ Object
returns generator source for a given generator-group.
-
#sources ⇒ Object
returns array of generator-group sources.
-
#types_of(name) ⇒ Object
returns array of generator-types for a given generator-group.
Constructor Details
#initialize ⇒ CodeGenerators
Returns a new instance of CodeGenerators.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/butterfly.rb', line 38 def initialize @generators = [] # loop through build in code generator groups and user code generator groups [GENERATOR_GROUPS, USER_GROUPS].each do |path| Dir[path].each do |file| @generators.push(GeneratorGroup.new(file)) if File.directory?(file) end end end |
Instance Attribute Details
#generators ⇒ Object
Returns the value of attribute generators.
36 37 38 |
# File 'lib/butterfly.rb', line 36 def generators @generators end |
Instance Method Details
#names ⇒ Object
returns array of generator-group names
50 51 52 |
# File 'lib/butterfly.rb', line 50 def names generators.map{ |generator| generator.name } end |
#source_of(name) ⇒ Object
returns generator source for a given generator-group
60 61 62 63 64 65 66 67 |
# File 'lib/butterfly.rb', line 60 def source_of(name) selected = generators.select { |n| n.name == name } if selected.length == 0 raise Butterfly::GeneratorSourceMissingError else selected[0].source end end |
#sources ⇒ Object
returns array of generator-group sources
55 56 57 |
# File 'lib/butterfly.rb', line 55 def sources generators.map{ |generator| generator.source } end |
#types_of(name) ⇒ Object
returns array of generator-types for a given generator-group
70 71 72 73 74 75 76 77 |
# File 'lib/butterfly.rb', line 70 def types_of(name) selected = generators.select { |n| n.name == name } if selected.length == 0 [] else selected[0].types end end |