Class: Cubic::Generator::Base
- Inherits:
-
Object
- Object
- Cubic::Generator::Base
- Defined in:
- lib/cubic/generators/base.rb
Overview
All generators (model, view, controller) inherit from the base class.
Direct Known Subclasses
App, Controller, Gemfile, Migrations, Model, View
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Instance Method Summary collapse
-
#callback ⇒ Object
If callback is not defined within a generator, this method will be called to avoid a ‘NoMethodError’.
-
#generate ⇒ Object
Generate takes an array of hashes from each generator, then creates a file from those params.
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
9 10 11 |
# File 'lib/cubic/generators/base.rb', line 9 def initialize @files = [] end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
7 8 9 |
# File 'lib/cubic/generators/base.rb', line 7 def files @files end |
Instance Method Details
#callback ⇒ Object
If callback is not defined within a generator, this method will be called to avoid a ‘NoMethodError’.
15 |
# File 'lib/cubic/generators/base.rb', line 15 def callback; end |
#generate ⇒ Object
Generate takes an array of hashes from each generator, then creates a file from those params. If a generator requires a unique file generation, this method will be overwritten in that file.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/cubic/generators/base.rb', line 21 def generate @files.each do |info| path = File.join(Config[:root_path], info[:path]) FileUtils.mkdir_p(path) unless File.directory?(path) full_path = File.join(path, info[:name]) File.open(full_path, 'w') { |f| f.write(info[:content]) } end callback end |