class Kumogata2::Client

Public Class Methods

get_template_path(file = nil) click to toggle source
# File lib/kumogata/template/ext/kumogata.rb, line 33
def self.get_template_path(file = nil)
  template_path = File.expand_path(File.join(File.dirname(__FILE__),
                                             '..', '..', '..','..', 'template'))
  template_path = File.join(template_path, "#{file}.rb") unless file.nil?
  template_path
end

Public Instance Methods

init(stack_name) click to toggle source
# File lib/kumogata/template/ext/kumogata.rb, line 7
def init(stack_name)
  begin
    base_template = ''
    File.open(Kumogata2::Client::get_template_path('_template'), 'r'){|f|
      base_template = f.read
    }
    raise 'initialize template is empty' if base_template.empty?

    new_template = "#{stack_name}.rb"
    if File.exists? new_template
      print "#{new_template} is already exists. Are sure want to overwrite? [y/N]: "
      answer = STDIN.gets.to_s.chomp
      return nil if answer.upcase != 'Y'
    end

    File.open(new_template, 'w'){|f|
      template = base_template.gsub('#{NAME}', stack_name)
      f.write(template)
    }
    Kumogata2::Logger::Helper.log(:info, "Saved template to #{stack_name}.rb".green)
  rescue => e
    Kumogata2::Logger::Helper.log(:error, "Failed to template #{stack_name} - #{e}".red)
  end
  nil
end