class Tumugi::Command::New::Generator
Attributes
name[R]
options[R]
Public Class Methods
new(name, options={})
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 10 def initialize(name, options={}) @name = name @options = options end
Public Instance Methods
context()
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 52 def context {} end
data_dir()
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 40 def data_dir nil end
dest_dir()
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 44 def dest_dir nil end
generate()
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 15 def generate if File.exist?(dest_dir) && !options[:force] logger.error "#{dest_dir} is already exists. Please delete it first" return false end logger.info "Create #{dest_dir}" FileUtils.mkdir_p(dest_dir) templates.each do |value| src_file, dest_file = value eruby = Erubis::Eruby.new(File.read(src_path(src_file))) eruby.filename = src_path(src_file) logger.info " Create #{dest_path(dest_file)}" FileUtils.mkdir_p(File.dirname(dest_path(dest_file))) File.write(dest_path(dest_file), eruby.result(context)) end unless post_messages.empty? post_messages.each{|msg| logger.info msg } end true end
logger()
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 60 def logger @logger ||= Tumugi::ScopedLogger.new("tumugi-new") end
post_messages()
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 56 def post_messages [] end
templates()
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 48 def templates [] end
Private Instance Methods
dest_path(file)
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 70 def dest_path(file) File.join(dest_dir, file) end
src_path(file)
click to toggle source
# File lib/tumugi/command/new/generator.rb, line 66 def src_path(file) File.join(data_dir, file) end