Class: AppsignalGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/appsignal/appsignal_generator.rb

Instance Method Summary collapse

Instance Method Details

#capyistrano_installObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/generators/appsignal/appsignal_generator.rb', line 24

def capyistrano_install
  deploy_file = File.expand_path(File.join('config', 'deploy.rb'))
  cap_file = File.expand_path('Capfile')
  if [deploy_file, cap_file].all? { |file| File.exists?(file) }
    file_contents = File.read(deploy_file)
    if (file_contents =~ /require (\'|\").\/appsignal\/capistrano/).nil?
      append_to_file deploy_file, "\nrequire 'appsignal/capistrano'\n"
    end
  else
    say_status :info, "No capistrano setup detected! Did you know you can "\
      "use the AppSignal CLI to notify AppSignal of deployments?", :yellow
    say_status "", "Run the following command for help:"
    say_status "", "appsignal notify_of_deploy -h"
  end
end

#check_keyObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/appsignal/appsignal_generator.rb', line 40

def check_key
  begin
    auth_check = ::Appsignal::AuthCheck.new(options.environment)
    result = auth_check.perform
    if result == '200'
      say_status :success, "AppSignal has confirmed authorisation!"
    elsif result == '401'
      say_status :error, "Push key not valid with AppSignal...", :red
    else
      say_status :error, "Could not confirm authorisation: "\
        "#{result.nil? ? 'nil' : result} at #{auth_check.uri}", :red
    end
  rescue Exception => e
    say_status :error, "Something went wrong while trying to authenticate "\
      "with AppSignal: #{e}", :red
  end
end

#copy_config_fileObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/appsignal/appsignal_generator.rb', line 10

def copy_config_file
  template_file = 'appsignal.yml'
  appsignal_file = File.join('config', template_file)
  if File.exists?(appsignal_file)
    if environment_setup?(appsignal_file)
      say_status :error, "Environment already setup", :red
    else
      append_to_file appsignal_file, "\n"+new_template_content(template_file)
    end
  else
    template template_file, appsignal_file
  end
end