Sha256: 2e9ec86ba5027e0450a04663929f8e64ac7072d7bb15f5c747d192281c4d7af9

Contents?: true

Size: 1.93 KB

Versions: 32

Compression:

Stored size: 1.93 KB

Contents

require 'forwardable'
require 'honeybadger/cli/main'
require 'honeybadger/cli/test'
require 'pathname'

module Honeybadger
  module CLI
    class Install
      extend Forwardable

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

      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

      private

      attr_reader :options, :api_key

      def_delegator :@shell, :say
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
honeybadger-4.9.0 lib/honeybadger/cli/install.rb
honeybadger-4.8.0 lib/honeybadger/cli/install.rb
honeybadger-4.7.3 lib/honeybadger/cli/install.rb
honeybadger-4.7.2 lib/honeybadger/cli/install.rb
honeybadger-4.7.1 lib/honeybadger/cli/install.rb
honeybadger-4.7.0 lib/honeybadger/cli/install.rb
honeybadger-4.6.0 lib/honeybadger/cli/install.rb
honeybadger-4.5.6 lib/honeybadger/cli/install.rb
honeybadger-4.5.5 lib/honeybadger/cli/install.rb
honeybadger-4.5.4 lib/honeybadger/cli/install.rb
honeybadger-4.5.3 lib/honeybadger/cli/install.rb
honeybadger-4.5.2 lib/honeybadger/cli/install.rb
honeybadger-4.5.1 lib/honeybadger/cli/install.rb
honeybadger-4.5.0 lib/honeybadger/cli/install.rb
honeybadger-4.4.2 lib/honeybadger/cli/install.rb
honeybadger-4.4.1 lib/honeybadger/cli/install.rb
honeybadger-4.4.0 lib/honeybadger/cli/install.rb
honeybadger-4.3.1 lib/honeybadger/cli/install.rb
honeybadger-4.3.0 lib/honeybadger/cli/install.rb
honeybadger-4.2.2 lib/honeybadger/cli/install.rb