require 'colorize' module Mutx class CreateAlert < Thor::Group include Thor::Actions desc "Create an Alert in Mutx" argument :name, type: :string, desc: 'alert name' def self.source_root File.dirname(__FILE__) + "/templates/" end def self.alert_folder "#{Dir.pwd}/alerts" end def self.alert_filename(alert_name) File.join(self.alert_folder, "#{alert_name}_alert.rb") end def check_alert_folder unless Dir.exist? self.class.alert_folder say "creating alert folder: #{self.class.alert_folder}".green empty_directory(self.class.alert_folder) else say "alert folder exists ( #{self.class.alert_folder} )".green end end def check_not_exist_alert raise Error, "alert exists ( #{ self.class.alert_filename(name) } )" if File.exists? self.class.alert_filename(name) end def create_alarm template 'mutx_alert.rb.tt', self.class.alert_filename(name) end def finish_message say 'Alert created!'.green say "please, edit: #{self.class.alert_filename(name)}".green end end end