Sha256: 648b91f0d752c3f60530cfc72e4cbe0c00be7f5f91d827a85b68ea31e84c42e8

Contents?: true

Size: 1.37 KB

Versions: 14

Compression:

Stored size: 1.37 KB

Contents

require 'rails'
require 'rollbar'

APP_PATH = File.expand_path('config/application', Dir.pwd)

module Rails
  class RollbarRunner
    class GemResolver
      def railties_gem
        Gem::Specification.find_by_name('railties')
      end
    end

    class LegacyGemResolver
      def railties_gem
        searcher = Gem::GemPathSearcher.new
        searcher.find('rails')
      end
    end

    attr_reader :command

    def initialize
      @command = ARGV[0]
    end

    def run
      prepare_environment

      rollbar_managed { eval_runner }
    end

    def prepare_environment
      require File.expand_path('../environment', APP_PATH)
      ::Rails.application.require_environment!
    end

    def eval_runner
      string_to_eval = File.read(runner_path)

      ::Rails.module_eval(<<-EOL, __FILE__, __LINE__ + 2)
          #{string_to_eval}
      EOL
    end

    def rollbar_managed
      yield
    rescue => e
      Rollbar.scope(:custom => { :command => command }).error(e)
      raise
    end

    def runner_path
      railties_gem_dir + '/lib/rails/commands/runner.rb'
    end

    def railties_gem
      resolver_class = Gem::Specification.respond_to?(:find_by_name) ? GemResolver : LegacyGemResolver
      gem = resolver_class.new.railties_gem

      abort 'railties gem not found' unless gem

      gem
    end

    def railties_gem_dir
      railties_gem.gem_dir
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rollbar-2.18.2 lib/rails/rollbar_runner.rb
rollbar-2.18.0 lib/rails/rollbar_runner.rb
rollbar-2.17.0 lib/rails/rollbar_runner.rb
rollbar-2.16.4 lib/rails/rollbar_runner.rb
rollbar-2.16.3 lib/rails/rollbar_runner.rb
rollbar-2.16.2 lib/rails/rollbar_runner.rb
rollbar-2.16.0 lib/rails/rollbar_runner.rb
rollbar-2.15.6 lib/rails/rollbar_runner.rb
rollbar-2.15.5 lib/rails/rollbar_runner.rb
rollbar-2.15.4 lib/rails/rollbar_runner.rb
rollbar-2.15.3 lib/rails/rollbar_runner.rb
rollbar-2.15.2 lib/rails/rollbar_runner.rb
rollbar-2.15.1 lib/rails/rollbar_runner.rb
rollbar-2.15.0 lib/rails/rollbar_runner.rb