Class: NewRelic::Plugin::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/newrelic_plugin/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Creates an instance of a configuration object, loading the configuration from the YAML configuration file. Note: this method should not be used directly, rather the global method config should be referenced instead.



26
27
28
29
# File 'lib/newrelic_plugin/config.rb', line 26

def initialize
  @options = YAML::load(Config.config_yaml) if Config.config_yaml
  @options = YAML::load(ERB.new(File.read(Config.config_file), 0, '<>').result) unless @options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/newrelic_plugin/config.rb', line 22

def options
  @options
end

Class Method Details

.configObject

Returns a memoized version of the configuration object.



77
78
79
# File 'lib/newrelic_plugin/config.rb', line 77

def self.config
  @instance||=NewRelic::Plugin::Config.new
end

.config_fileObject



58
59
60
# File 'lib/newrelic_plugin/config.rb', line 58

def self.config_file
  @config_file||="config/newrelic_plugin.yml"
end

.config_file=(config_file) ⇒ Object

Set the name of the configuration file:

NewRelic::Plugin::Config.config_file="lib/config.yml"


53
54
55
56
57
# File 'lib/newrelic_plugin/config.rb', line 53

def self.config_file= config_file
  @config_file=config_file
  @config_yaml=nil
  @instance=nil
end

.config_yamlObject



71
72
73
# File 'lib/newrelic_plugin/config.rb', line 71

def self.config_yaml
  @config_yaml
end

.config_yaml=(config_yaml) ⇒ Object

Set the content of the configuration as a YAML string

NewRelic::Plugin::Config.config_yaml="newrelic:\n  test: 2\n  test2: four\nagents:\n  test: 4\n  test2: six\n"


66
67
68
69
70
# File 'lib/newrelic_plugin/config.rb', line 66

def self.config_yaml= config_yaml
  @config_yaml=config_yaml
  @config_file=nil
  @instance=nil
end

Instance Method Details

#agentsObject

Return a hash of agent configuration information.

Usage: NewRelic::Plugin::Config.config.agents



44
45
46
# File 'lib/newrelic_plugin/config.rb', line 44

def agents
  @options["agents"]
end

#newrelicObject

Return a hash of NewRelic configuration information.

Usage: NewRelic::Plugin::Config.config.newrelic



36
37
38
# File 'lib/newrelic_plugin/config.rb', line 36

def newrelic
  @options["newrelic"]
end