Sha256: 718bc2c6a4725a0b10c940b61c246419ae49a51abd23565d45f69a25417c37ff

Contents?: true

Size: 1.11 KB

Versions: 7

Compression:

Stored size: 1.11 KB

Contents

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      

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mutx-0.2.9 lib/generators/create_alert.rb
mutx-0.2.8 lib/generators/create_alert.rb
mutx-0.2.7 lib/generators/create_alert.rb
mutx-0.2.6 lib/generators/create_alert.rb
mutx-0.2.5 lib/generators/create_alert.rb
mutx-0.2.4 lib/generators/create_alert.rb
mutx-0.2.3 lib/generators/create_alert.rb