lib/toycol/template_generator.rb in toycol-0.3.0 vs lib/toycol/template_generator.rb in toycol-0.3.1

- old
+ new

@@ -1,12 +1,14 @@ # frozen_string_literal: true module Toycol class TemplateGenerator + include Helper + class << self def generate!(type:, name:) - raise StandardError, "Unknown Type: This type of template can't be generated" unless valid? type + raise Error, "Unknown Type: This type of template can't be generated" unless valid? type if type == "all" new(name, "protocol").generate! new(name, "app").generate! else @@ -25,14 +27,14 @@ @name = name @type = type end def generate! - raise StandardError, "#{filename} already exists" unless Dir.glob(filename).empty? + raise Error, "#{filename} already exists" unless Dir.glob(filename).empty? File.open(filename, "w") { |f| f.print template_text_for_new } - puts "Generate #{filename} in #{FileUtils.pwd}" + logger "Generate #{filename} in #{FileUtils.pwd}" end private def filename @@ -50,11 +52,11 @@ end end def template_text case @type - when "protocol" then File.open("lib/toycol/templates/protocol.txt", "r", &:read) - when "app" then File.open("lib/toycol/templates/application.txt", "r", &:read) + when "protocol" then File.open("#{__dir__}/templates/protocol.txt", "r", &:read) + when "app" then File.open("#{__dir__}/templates/application.txt", "r", &:read) end end end end