Class: Rollbar::Generators::RollbarGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/rollbar/rollbar_generator.rb

Instance Method Summary collapse

Instance Method Details

#access_token_configured?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/generators/rollbar/rollbar_generator.rb', line 58

def access_token_configured?
  File.exist?('config/initializers/rollbar.rb')
end

#access_token_exprObject



50
51
52
53
54
55
56
# File 'lib/generators/rollbar/rollbar_generator.rb', line 50

def access_token_expr
  if access_token === :use_env_sentinel
    "ENV['ROLLBAR_ACCESS_TOKEN']"
  else
    "'#{access_token}'"
  end
end

#create_initializerObject



13
14
15
16
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
# File 'lib/generators/rollbar/rollbar_generator.rb', line 13

def create_initializer
  say 'creating initializer...'
  if access_token_configured?
    say "It looks like you've already configured Rollbar."
    say 'To re-create the config file, remove it first: ' \
      'config/initializers/rollbar.rb'
    exit
  end

  begin
    require 'ey_config'
  rescue LoadError
    # Skip loading
  end

  if defined? EY::Config
    say 'Access token will be read from Engine Yard configuration'
  elsif access_token === :use_env_sentinel
    say 'Generator run without an access token; assuming you want to ' \
      'configure using an environment variable.'
    say "You'll need to add an environment variable ROLLBAR_ACCESS_TOKEN " \
      'with your access token:'
    say "\n$ export ROLLBAR_ACCESS_TOKEN=yourtokenhere"
    say "\nIf that's not what you wanted to do:"
    say "\n$ rm config/initializers/rollbar.rb"
    say '$ rails generate rollbar yourtokenhere'
    say "\n"
  else
    say 'access token: ' << access_token
  end

  template 'initializer.erb', 'config/initializers/rollbar.rb',
           :assigns => { :access_token => access_token_expr }

  # TODO: run rake test task
end