Class: Sonar::Connector::Config
- Inherits:
-
Object
- Object
- Sonar::Connector::Config
- Defined in:
- lib/sonar_connector/config.rb
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
readonly
base params.
-
#connectors ⇒ Object
readonly
Returns the value of attribute connectors.
-
#connectors_dir ⇒ Object
readonly
Returns the value of attribute connectors_dir.
-
#controller_log_file ⇒ Object
readonly
Returns the value of attribute controller_log_file.
-
#email_settings ⇒ Object
readonly
Returns the value of attribute email_settings.
-
#log_dir ⇒ Object
readonly
Returns the value of attribute log_dir.
-
#log_file_max_size ⇒ Object
readonly
Returns the value of attribute log_file_max_size.
-
#log_files_to_keep ⇒ Object
readonly
Returns the value of attribute log_files_to_keep.
-
#log_level ⇒ Object
readonly
configurable: logger params.
-
#status_file ⇒ Object
readonly
Returns the value of attribute status_file.
Class Method Summary collapse
-
.load(config_file) ⇒ Object
Entry-point for creating and setting the CONFIG instance.
-
.read_json_file(config_file) ⇒ Object
Helper method to read and parse JSON file from disk.
Instance Method Summary collapse
-
#initialize(config_file) ⇒ Config
constructor
A new instance of Config.
- #parse ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Config
Returns a new instance of Config.
33 34 35 |
# File 'lib/sonar_connector/config.rb', line 33 def initialize(config_file) @config_file = config_file end |
Instance Attribute Details
#base_dir ⇒ Object (readonly)
base params
8 9 10 |
# File 'lib/sonar_connector/config.rb', line 8 def base_dir @base_dir end |
#connectors ⇒ Object (readonly)
Returns the value of attribute connectors.
13 14 15 |
# File 'lib/sonar_connector/config.rb', line 13 def connectors @connectors end |
#connectors_dir ⇒ Object (readonly)
Returns the value of attribute connectors_dir.
10 11 12 |
# File 'lib/sonar_connector/config.rb', line 10 def connectors_dir @connectors_dir end |
#controller_log_file ⇒ Object (readonly)
Returns the value of attribute controller_log_file.
11 12 13 |
# File 'lib/sonar_connector/config.rb', line 11 def controller_log_file @controller_log_file end |
#email_settings ⇒ Object (readonly)
Returns the value of attribute email_settings.
14 15 16 |
# File 'lib/sonar_connector/config.rb', line 14 def email_settings @email_settings end |
#log_dir ⇒ Object (readonly)
Returns the value of attribute log_dir.
9 10 11 |
# File 'lib/sonar_connector/config.rb', line 9 def log_dir @log_dir end |
#log_file_max_size ⇒ Object (readonly)
Returns the value of attribute log_file_max_size.
18 19 20 |
# File 'lib/sonar_connector/config.rb', line 18 def log_file_max_size @log_file_max_size end |
#log_files_to_keep ⇒ Object (readonly)
Returns the value of attribute log_files_to_keep.
19 20 21 |
# File 'lib/sonar_connector/config.rb', line 19 def log_files_to_keep @log_files_to_keep end |
#log_level ⇒ Object (readonly)
configurable: logger params
17 18 19 |
# File 'lib/sonar_connector/config.rb', line 17 def log_level @log_level end |
#status_file ⇒ Object (readonly)
Returns the value of attribute status_file.
12 13 14 |
# File 'lib/sonar_connector/config.rb', line 12 def status_file @status_file end |
Class Method Details
.load(config_file) ⇒ Object
Entry-point for creating and setting the CONFIG instance. Give it a path to the JSON settings file and it’ll do the rest.
23 24 25 26 |
# File 'lib/sonar_connector/config.rb', line 23 def self.load(config_file) config = Config.new(config_file).parse Sonar::Connector.const_set("CONFIG", config) end |
.read_json_file(config_file) ⇒ Object
Helper method to read and parse JSON file from disk. Abstracted for testing purposes.
29 30 31 |
# File 'lib/sonar_connector/config.rb', line 29 def self.read_json_file(config_file) JSON.parse IO.read(config_file) end |
Instance Method Details
#parse ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sonar_connector/config.rb', line 37 def parse @raw_config = Config.read_json_file(config_file) # extract the core config params @base_dir = parse_base_dir @raw_config["base_dir"] @log_dir = File.join @base_dir, 'log' @connectors_dir = File.join @base_dir, 'var' @controller_log_file = File.join @log_dir, 'controller.log' @status_file = File.join @base_dir, 'status.yml' @log_level = parse_log_level @raw_config["log_level"] @log_file_max_size = parse_log_file_max_size @raw_config["log_file_max_size"] @log_files_to_keep = parse_log_files_to_keep @raw_config["log_files_to_keep"] @email_settings = parse_email_settings @raw_config["email_settings"] # extract each connector, locate its class and attempt to parse its config @connectors = parse_connectors @raw_config["connectors"] associate_connector_dependencies! @connectors self rescue JSON::ParserError => e raise InvalidConfig.new("Config file #{config_file} is not in a valid JSON format. Please check the contents carefully. This is the exact error: \n#{e.}") end |