class Cubic::Generator::Base

All generators (model, view, controller) inherit from the base class.

Attributes

files[R]

Public Class Methods

new() click to toggle source
# File lib/cubic/generators/base.rb, line 9
def initialize
  @files = []
end

Public Instance Methods

callback() click to toggle source

If callback is not defined within a generator, this method will be called to avoid a 'NoMethodError'.

# File lib/cubic/generators/base.rb, line 15
def callback; end
generate() click to toggle source

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.

# 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