Class: Rails::RollbarRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/rollbar_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRollbarRunner

Returns a new instance of RollbarRunner.



16
17
18
# File 'lib/rails/rollbar_runner.rb', line 16

def initialize
  @command = ARGV[0]
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



14
15
16
# File 'lib/rails/rollbar_runner.rb', line 14

def command
  @command
end

Instance Method Details

#eval_runnerObject



31
32
33
34
35
36
37
# File 'lib/rails/rollbar_runner.rb', line 31

def eval_runner
  if Gem::Version.new(Rails.version) >= Gem::Version.new('5.1.0')
    rails5_runner
  else
    legacy_runner
  end
end

#legacy_runnerObject



39
40
41
42
43
44
45
# File 'lib/rails/rollbar_runner.rb', line 39

def legacy_runner
  string_to_eval = File.read(runner_path)

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

#prepare_environmentObject



26
27
28
29
# File 'lib/rails/rollbar_runner.rb', line 26

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

#rails5_runnerObject



47
48
49
50
51
# File 'lib/rails/rollbar_runner.rb', line 47

def rails5_runner
  require 'rails/command'

  Rails::Command.invoke 'runner', ARGV
end

#railties_gemObject



64
65
66
67
68
69
70
# File 'lib/rails/rollbar_runner.rb', line 64

def railties_gem
  gem = Gem::Specification.find_by_name('railties')

  abort 'railties gem not found' unless gem

  gem
end

#railties_gem_dirObject



72
73
74
# File 'lib/rails/rollbar_runner.rb', line 72

def railties_gem_dir
  railties_gem.gem_dir
end

#rollbar_managedObject



53
54
55
56
57
58
# File 'lib/rails/rollbar_runner.rb', line 53

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

#runObject



20
21
22
23
24
# File 'lib/rails/rollbar_runner.rb', line 20

def run
  prepare_environment

  rollbar_managed { eval_runner }
end

#runner_pathObject



60
61
62
# File 'lib/rails/rollbar_runner.rb', line 60

def runner_path
  "#{railties_gem_dir}/lib/rails/commands/runner.rb"
end