Module: NewRelic::Control::ClassMethods
- Included in:
- NewRelic::Control
- Defined in:
- lib/new_relic/control/class_methods.rb
Overview
class-level methods for lazy creation of NewRelic::Control and NewRelic::LocalEnvironment instances.
Instance Method Summary collapse
-
#instance(create = true) ⇒ Object
Access the Control singleton, lazy initialized.
-
#load_framework_class(framework) ⇒ Object
Loads the specified framework class from the NewRelic::Control::Frameworks module.
-
#load_test_framework ⇒ Object
nb this does not ‘load test’ the framework, it loads the ‘test framework’.
-
#local_env ⇒ Object
Access the LocalEnvironment singleton, lazy initialized.
-
#new_instance ⇒ Object
Create the concrete class for environment specific behavior.
-
#newrelic_root ⇒ Object
The root directory for the plugin or gem.
-
#reset ⇒ Object
clear out memoized Control and LocalEnv instances.
Instance Method Details
#instance(create = true) ⇒ Object
Access the Control singleton, lazy initialized. Default will instantiate a new instance or pass false to defer
8 9 10 |
# File 'lib/new_relic/control/class_methods.rb', line 8 def instance(create=true) @instance ||= create && new_instance end |
#load_framework_class(framework) ⇒ Object
Loads the specified framework class from the NewRelic::Control::Frameworks module
41 42 43 44 45 46 47 48 49 |
# File 'lib/new_relic/control/class_methods.rb', line 41 def load_framework_class(framework) begin require "new_relic/control/frameworks/#{framework}" rescue LoadError # maybe it is already loaded by some external system # i.e. rpm_contrib or user extensions? end NewRelic::Control::Frameworks.const_get(framework.to_s.capitalize) end |
#load_test_framework ⇒ Object
nb this does not ‘load test’ the framework, it loads the ‘test framework’
33 34 35 36 37 |
# File 'lib/new_relic/control/class_methods.rb', line 33 def load_test_framework config = File.(File.join('..','..','..','..', "test","config","newrelic.yml"), __FILE__) require "config/test_control" NewRelic::Control::Frameworks::Test.new(local_env, config) end |
#local_env ⇒ Object
Access the LocalEnvironment singleton, lazy initialized
19 20 21 |
# File 'lib/new_relic/control/class_methods.rb', line 19 def local_env @local_env ||= NewRelic::LocalEnvironment.new end |
#new_instance ⇒ Object
Create the concrete class for environment specific behavior
24 25 26 27 28 29 30 |
# File 'lib/new_relic/control/class_methods.rb', line 24 def new_instance if Agent.config[:framework] == :test load_test_framework else load_framework_class(Agent.config[:framework]).new(local_env) end end |
#newrelic_root ⇒ Object
The root directory for the plugin or gem
52 53 54 |
# File 'lib/new_relic/control/class_methods.rb', line 52 def newrelic_root File.(File.join("..", "..", "..", ".."), __FILE__) end |
#reset ⇒ Object
clear out memoized Control and LocalEnv instances
13 14 15 16 |
# File 'lib/new_relic/control/class_methods.rb', line 13 def reset @instance = nil @local_env = nil end |