Class: NewRelic::Config::Rails

Inherits:
NewRelic::Config show all
Defined in:
lib/new_relic/config/rails.rb

Instance Attribute Summary

Attributes inherited from NewRelic::Config

#log_file

Instance Method Summary collapse

Methods inherited from NewRelic::Config

#[], #[]=, #api_server, #app_config_info, #app_name, #connect_to_server?, #developer_mode?, #fetch, format_message, #http_connection, instance, #local_env, #log, #log!, #newrelic_root, #proxy_server, #server, #set_config, #settings, #setup_log, #to_s, #tracers_enabled?, #use_ssl?

Instance Method Details

#appObject



3
# File 'lib/new_relic/config/rails.rb', line 3

def app; :rails; end

#envObject



5
6
7
# File 'lib/new_relic/config/rails.rb', line 5

def env
  @env ||= RAILS_ENV
end

#install_developer_mode(rails_config) ⇒ Object



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
67
68
# File 'lib/new_relic/config/rails.rb', line 27

def install_developer_mode(rails_config)
  controller_path = File.join(newrelic_root, 'ui', 'controllers')
  helper_path = File.join(newrelic_root, 'ui', 'helpers')

  if defined? ActiveSupport::Dependencies
    Dir["#{helper_path}/*.rb"].each { |f| require f }
    Dir["#{controller_path}/*.rb"].each { |f| require f }
  elsif defined? Dependencies.load_paths
    Dependencies.load_paths << controller_path
    Dependencies.load_paths << helper_path
  else
    to_stderr "ERROR: Rails version #{(RAILS_GEM_VERSION) ? RAILS_GEM_VERSION : ''} too old for developer mode to work."
    return
  end
  
  install_devmode_route
  
  
  # If we have the config object then add the controller path to the list.
  # Otherwise we have to assume the controller paths have already been
  # set and we can just append newrelic.
  
  if rails_config
    rails_config.controller_paths << controller_path
  else
    current_paths = ActionController::Routing.controller_paths
    if current_paths.nil? || current_paths.empty?
      to_stderr "WARNING: Unable to modify the routes in this version of Rails.  Developer mode not available."
    end
    current_paths << controller_path
  end
  
  #ActionController::Routing::Routes.reload! unless NewRelic::Config.instance['skip_developer_route']
  
  # inform user that the dev edition is available if we are running inside
  # a webserver process
  if local_env.identifier
    port = local_env.identifier.to_s =~ /^\d+/ ? ":#{local_env.identifier}" : ":port" 
    to_stderr "NewRelic Agent Developer Mode enabled."
    to_stderr "To view performance information, go to http://localhost#{port}/newrelic"
  end
end

#log_pathObject



12
13
14
15
16
17
# File 'lib/new_relic/config/rails.rb', line 12

def log_path
  path = ::RAILS_DEFAULT_LOGGER.instance_eval do
    File.dirname(@log.path) rescue File.dirname(@logdev.filename) 
  end rescue "#{root}/log"
  File.expand_path(path)
end

#rootObject



8
9
10
# File 'lib/new_relic/config/rails.rb', line 8

def root
  RAILS_ROOT
end

#start_plugin(rails_config = nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/new_relic/config/rails.rb', line 19

def start_plugin(rails_config=nil)
  if !tracers_enabled? || !start_agent
    require 'new_relic/shim_agent'
  else
    install_developer_mode rails_config if developer_mode?
  end
end