Class: Configuration::ConfigurationManager
- Inherits:
-
Object
- Object
- Configuration::ConfigurationManager
- Includes:
- Singleton
- Defined in:
- lib/configuration/configuration_manager.rb
Overview
Configuration manager
Constant Summary collapse
- CONFIGURATION_FILENAME =
".jira-logwork.yml"
Instance Attribute Summary collapse
-
#configuration_data ⇒ Object
Returns the value of attribute configuration_data.
Instance Method Summary collapse
-
#configuration_path ⇒ String
The configuration path.
-
#initialize ⇒ ConfigurationManager
constructor
A new instance of ConfigurationManager.
-
#jira_server_url ⇒ String
Read JIRA server URL configuration file.
-
#save_configuration ⇒ Object
Writes configuration jira-worklog configuration folder.
-
#update_jira_server_url(url) ⇒ Object
Update login credentials in configuration file.
Constructor Details
#initialize ⇒ ConfigurationManager
Returns a new instance of ConfigurationManager.
35 36 37 |
# File 'lib/configuration/configuration_manager.rb', line 35 def initialize self.configuration_data = configured? ? read_configuration : {} end |
Instance Attribute Details
#configuration_data ⇒ Object
Returns the value of attribute configuration_data.
33 34 35 |
# File 'lib/configuration/configuration_manager.rb', line 33 def configuration_data @configuration_data end |
Instance Method Details
#configuration_path ⇒ String
The configuration path
78 79 80 |
# File 'lib/configuration/configuration_manager.rb', line 78 def configuration_path File.join(home_dir, Constants::ROOT_CONFIGURATION_FOLDER_NAME, CONFIGURATION_FILENAME) end |
#jira_server_url ⇒ String
Read JIRA server URL configuration file
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/configuration/configuration_manager.rb', line 42 def jira_server_url if configuration_data[:jira_server_url].nil? raise LogworkException::ConfigurationJiraURLNotFound.new, "Cannot read JIRA server URL from configuration file at '#{configuration_path}'." end unless Utilities.valid_url?(configuration_data[:jira_server_url]) raise LogworkException::InvalidURL.new, "Invalid JIRA Server URL in '#{configuration_path}'" end configuration_data[:jira_server_url] end |
#save_configuration ⇒ Object
Writes configuration jira-worklog configuration folder.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/configuration/configuration_manager.rb', line 64 def save_configuration create_config_dir_if_needed unless configuration_writable? raise LogworkException::ConfigurationFileNotFound.new, "Configuration cannot be saved at '#{configuration_path}'" end File.write(configuration_path, configuration_data.deep_stringify_keys.to_yaml) read_configuration end |
#update_jira_server_url(url) ⇒ Object
Update login credentials in configuration file
56 57 58 59 60 61 |
# File 'lib/configuration/configuration_manager.rb', line 56 def update_jira_server_url(url) raise LogworkException::InvalidURL.new, "Invalid JIRA Server URL." unless Utilities.valid_url?(url) configuration_data[:jira_server_url] = url save_configuration end |