Class: Sonar::Connector::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_dirObject (readonly)

base params



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

def base_dir
  @base_dir
end

#connectorsObject (readonly)

Returns the value of attribute connectors.



13
14
15
# File 'lib/sonar_connector/config.rb', line 13

def connectors
  @connectors
end

#connectors_dirObject (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_fileObject (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_settingsObject (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_dirObject (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_sizeObject (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_keepObject (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_levelObject (readonly)

configurable: logger params



17
18
19
# File 'lib/sonar_connector/config.rb', line 17

def log_level
  @log_level
end

#status_fileObject (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

#parseObject



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.message}")
end