Class: Alonzo::Generator
- Inherits:
-
Object
- Object
- Alonzo::Generator
- Defined in:
- lib/alonzo/generator.rb
Defined Under Namespace
Classes: RbClassGenerator
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#generator ⇒ Object
readonly
Returns the value of attribute generator.
-
#generator_class ⇒ Object
readonly
Returns the value of attribute generator_class.
-
#output ⇒ Object
Returns the value of attribute output.
-
#root ⇒ Object
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(args, options = {}) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(args, options = {}) ⇒ Generator
Returns a new instance of Generator.
92 93 94 95 96 97 98 99 100 |
# File 'lib/alonzo/generator.rb', line 92 def initialize(args, = {}) self.args = args self.output = .delete(:output) || STDOUT self.root = .delete(:root) || Dir.pwd generator_klass_name = "#{[:type]}_generator".classify @generator_class = "#{self.class.name}::#{generator_klass_name}".constantize @generator = generator_class.new(args, root) end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
84 85 86 |
# File 'lib/alonzo/generator.rb', line 84 def args @args end |
#generator ⇒ Object (readonly)
Returns the value of attribute generator.
85 86 87 |
# File 'lib/alonzo/generator.rb', line 85 def generator @generator end |
#generator_class ⇒ Object (readonly)
Returns the value of attribute generator_class.
85 86 87 |
# File 'lib/alonzo/generator.rb', line 85 def generator_class @generator_class end |
#output ⇒ Object
Returns the value of attribute output.
84 85 86 |
# File 'lib/alonzo/generator.rb', line 84 def output @output end |
#root ⇒ Object
Returns the value of attribute root.
84 85 86 |
# File 'lib/alonzo/generator.rb', line 84 def root @root end |
Class Method Details
.generate(args, options = {}) ⇒ Object
87 88 89 90 |
# File 'lib/alonzo/generator.rb', line 87 def self.generate(args, = {}) generator = new(args, ) generator.generate end |
Instance Method Details
#generate ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/alonzo/generator.rb', line 102 def generate output.puts "Generating #{generator_class} files" generator.files.each do |file| output.puts " #{file[:name]}" FileUtils.mkdir_p(File.dirname(file[:name])) File.open(file[:name], "w") { |f| f << file[:content] } end end |