class AirbrakeGenerator

Public Class Methods

source_root() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 21
def self.source_root
  @_airbrake_source_root ||= File.expand_path("../../../../../generators/airbrake/templates", __FILE__)
end

Public Instance Methods

install() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 25
def install
  ensure_api_key_was_configured
  ensure_plugin_is_not_present
  append_capistrano_hook if capistrano_present?
  generate_initializer unless api_key_configured?
  determine_api_key if heroku?
  test_airbrake
end

Private Instance Methods

api_key_configured?() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 133
def api_key_configured?
  File.exists?('config/initializers/airbrake.rb')
end
api_key_expression() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 84
def api_key_expression
  if options[:api_key]
    "'#{options[:api_key]}'"
  elsif options[:heroku]
    "ENV['AIRBRAKE_API_KEY']"
  end
end
append_capistrano_hook() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 56
def append_capistrano_hook
  if capistrano_version < Gem::Version.new('3')
    append_file('config/deploy.rb', capistrano2_hook)
  else
    append_file('config/deploy.rb', capistrano3_hook)
  end
end
capistrano2_hook() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 68
  def capistrano2_hook
    <<-HOOK

require './config/boot'
require 'airbrake/capistrano'
    HOOK
  end
capistrano3_hook() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 76
  def capistrano3_hook
    <<-HOOK

require 'airbrake/capistrano3'
after "deploy:finished", "airbrake:deploy"
    HOOK
  end
capistrano_present?() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 50
def capistrano_present?
  !Gem.loaded_specs['capistrano'].nil? &&
    File.exists?('config/deploy.rb') &&
    File.exists?('Capfile')
end
capistrano_version() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 64
def capistrano_version
  Gem.loaded_specs['capistrano'].version
end
configuration_output() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 145
  def configuration_output
    output = <<-eos
Airbrake.configure do |config|
  config.api_key = #{api_key_expression}
    eos

    output << "  config.secure = true\n" if secure?
    output << "  config.test_mode = true\n" if test_mode?
    output << "end"
  end
determine_api_key() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 96
def determine_api_key
  puts "Attempting to determine your API Key from Heroku..."
  ENV['AIRBRAKE_API_KEY'] = heroku_api_key
  if ENV['AIRBRAKE_API_KEY'] =~ /\S/
    puts "... Done."
    puts "Heroku's Airbrake API Key is '#{ENV['AIRBRAKE_API_KEY']}'"
  else
    puts "... Failed."
    puts "WARNING: We were unable to detect the Airbrake API Key from your Heroku environment."
    puts "Your Heroku application environment may not be configured correctly."
    exit 1
  end
end
ensure_api_key_was_configured() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 36
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/airbrake.rb"
    exit
  end
end
ensure_plugin_is_not_present() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 43
def ensure_plugin_is_not_present
  if plugin_is_present?
    puts "You must first remove the airbrake plugin. Please run: script/plugin remove airbrake"
    exit
  end
end
generate_initializer() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 92
def generate_initializer
  template 'initializer.rb', 'config/initializers/airbrake.rb'
end
heroku?() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 127
def heroku?
  options[:heroku] ||
    system("grep AIRBRAKE_API_KEY config/initializers/airbrake.rb") ||
    system("grep AIRBRAKE_API_KEY config/environment.rb")
end
heroku_api_key() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 115
def heroku_api_key
  heroku_var("AIRBRAKE_API_KEY",options[:app]).split.find {|x| x if x =~ /\S/}
end
heroku_var(var,app_name = nil) click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 110
def heroku_var(var,app_name = nil)
  app = app_name ? "-a #{app_name}" : ''
  `heroku config:get #{var} #{app}`
end
plugin_is_present?() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 141
def plugin_is_present?
  File.exists?('vendor/plugins/airbrake')
end
secure?() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 119
def secure?
  options[:secure]
end
test_airbrake() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 137
def test_airbrake
  puts run("rake airbrake:test")
end
test_mode?() click to toggle source
# File lib/rails/generators/airbrake/airbrake_generator.rb, line 123
def test_mode?
  options[:test_mode]
end