module Mmtrix::Control::ClassMethods
class-level methods for lazy creation of Mmtrix::Control
and Mmtrix::LocalEnvironment
instances.
Public Instance Methods
instance(create=true)
click to toggle source
Access the Control
singleton, lazy initialized. Default will instantiate a new instance or pass false to defer
# File lib/mmtrix/control/class_methods.rb, line 12 def instance(create=true) @instance ||= create && new_instance end
load_framework_class(framework)
click to toggle source
Loads the specified framework class from the Mmtrix::Control::Frameworks
module
# File lib/mmtrix/control/class_methods.rb, line 45 def load_framework_class(framework) begin require "mmtrix/control/frameworks/#{framework}" rescue LoadError # maybe it is already loaded by some external system # i.e. rpm_contrib or user extensions? end Mmtrix::Control::Frameworks.const_get(framework.to_s.capitalize) end
load_test_framework()
click to toggle source
nb this does not ‘load test’ the framework, it loads the ‘test framework’
# File lib/mmtrix/control/class_methods.rb, line 37 def load_test_framework config = File.expand_path(File.join('..','..','..','..', "test","config","mmtrix.yml"), __FILE__) require "config/test_control" Mmtrix::Control::Frameworks::Test.new(local_env, config) end
local_env()
click to toggle source
Access the LocalEnvironment
singleton, lazy initialized
# File lib/mmtrix/control/class_methods.rb, line 23 def local_env @local_env ||= Mmtrix::LocalEnvironment.new end
mmtrix_root()
click to toggle source
The root directory for the plugin or gem
# File lib/mmtrix/control/class_methods.rb, line 56 def mmtrix_root File.expand_path(File.join("..", "..", "..", ".."), __FILE__) end
new_instance()
click to toggle source
Create the concrete class for environment specific behavior
# File lib/mmtrix/control/class_methods.rb, line 28 def new_instance if Agent.config[:framework] == :test load_test_framework else load_framework_class(Agent.config[:framework]).new(local_env) end end
reset()
click to toggle source
clear out memoized Control
and LocalEnv instances
# File lib/mmtrix/control/class_methods.rb, line 17 def reset @instance = nil @local_env = nil end