Sha256: 0e89dfaab7271871ac141155ae719153e65779e5270fa482928ffc3770cdf906

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

require 'rails/generators'

class ErrornotGenerator < Rails::Generators::Base

  class_option :api_key, :aliases => "-k", :type => :string, :desc => "Your Errornot API key"
  class_option :heroku, :type => :boolean, :desc => "Use the Heroku addon to provide your Hoptoad API key"
  class_option :server, :type => :string, :desc => "Your host of Errornot"

  def self.source_root
    @_errornot_source_root ||= File.expand_path("../../../../../generators/errornot/templates", __FILE__)
  end

  def install
    ensure_api_key_was_configured
    generate_initializer unless api_key_configured?
    test_errornot
  end

  private

  def ensure_api_key_was_configured
    if !options[:api_key] && !options[:heroku] && !api_key_configured?
      puts "Must pass --api-key or --heroku or create config/initializers/errornot.rb"
      exit
    end
    if !options[:server] && !api_key_configured?
      puts "Must pass --server or create config/initializers/errornot.rb"
      exit
    end
  end

  def api_key_expression
    s = if options[:api_key]
          "'#{options[:api_key]}'"
        elsif options[:heroku]
          "ENV['HOPTOAD_API_KEY']"
        end
  end

  def generate_initializer
    template 'initializer.rb', 'config/initializers/errornot.rb'
  end

  def api_key_configured?
    File.exists?('config/initializers/errornot.rb')
  end

  def test_errornot
    puts run("rake errornot:test --trace")
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
errornot_notifier-1.1.1 lib/rails/generators/errornot/errornot_generator.rb
errornot_notifier-1.1.0 lib/rails/generators/errornot/errornot_generator.rb