Class: Honeybadger::CLI::Install Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/honeybadger/cli/install.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Constructor Details

#initialize(options, api_key) ⇒ Install

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Install.



11
12
13
14
15
# File 'lib/honeybadger/cli/install.rb', line 11

def initialize(options, api_key)
  @options = options
  @api_key = api_key
  @shell = ::Thor::Base.shell.new
end

Instance Method Details

#runObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/honeybadger/cli/install.rb', line 17

def run
  say("Installing Honeybadger #{VERSION}")

  begin
    require File.join(Dir.pwd, 'config', 'application.rb')
    raise LoadError unless defined?(::Rails.application)
    root = Rails.root
    config_root = root.join('config')
  rescue LoadError
    root = config_root = Pathname.new(Dir.pwd)
  end

  config_path = config_root.join('honeybadger.yml')

  if config_path.exist?
    say("You're already on Honeybadger, so you're all set.", :yellow)
  else
    say("Writing configuration to: #{config_path}", :yellow)

    path = config_path

    if path.exist?
      say("The configuration file #{config_path} already exists.", :red)
      exit(1)
    elsif !path.dirname.writable?
      say("The configuration path #{config_path.dirname} is not writable.", :red)
      exit(1)
    end

    default_env = defined?(::Rails.application) ? "Rails.env" : "ENV['RUBY_ENV'] || ENV['RACK_ENV']"
    default_root = defined?(::Rails.application) ? "Rails.root.to_s" : "Dir.pwd"
    File.open(path, 'w+') do |file|
      file.write(<<-CONFIG)
---
# For more options, see https://docs.honeybadger.io/lib/ruby/gem-reference/configuration

api_key: '#{api_key}'

# The environment your app is running in.
env: "<%= #{default_env} %>"

# The absolute path to your project folder.
root: "<%= #{default_root} %>"

# Honeybadger won't report errors in these environments.
development_environments:
- test
- development
- cucumber

# By default, Honeybadger won't report errors in the development_environments.
# You can override this by explicitly setting report_data to true or false.
# report_data: true

# The current Git revision of your project. Defaults to the last commit hash.
# revision: null

# Enable verbose debug logging (useful for troubleshooting).
debug: false

# Enable Honeybadger Insights
insights:
  enabled: #{options["insights"]}
CONFIG
      if (connection = options.slice("host", "ui_host")).any?
        file.puts("\n# Override hosts\nconnection:")
        connection.each {|k,v| file.puts("  #{k}: '#{v}'") }
      end
    end
  end

  if (capfile = root.join('Capfile')).exist?
    if capfile.read.match(/honeybadger/)
      say("Detected Honeybadger in Capfile; skipping Capistrano installation.", :yellow)
    else
      say("Appending Capistrano tasks to: #{capfile}", :yellow)
      File.open(capfile, 'a') do |f|
        f.puts("\nrequire 'capistrano/honeybadger'")
      end
    end
  end

  Test.new({install: true}.freeze).run
end