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
# 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

    File.open(path, 'w+') do |file|
      file.write(<<-CONFIG)
---
api_key: '#{api_key}'
CONFIG
    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