Class: Sonar::Connector::Status
- Inherits:
-
Object
- Object
- Sonar::Connector::Status
- Defined in:
- lib/sonar_connector/status.rb
Overview
Represents the status and statistics collected by various connectors and is responsible for accessing, updating and persisting the status YAML file.
Instance Method Summary collapse
- #[](group) ⇒ Object
- #[]=(group, hash) ⇒ Object
-
#initialize(config) ⇒ Status
constructor
A new instance of Status.
- #load_status ⇒ Object
- #save_status ⇒ Object
- #set(group, key, value) ⇒ Object
Constructor Details
#initialize(config) ⇒ Status
Returns a new instance of Status.
8 9 10 11 |
# File 'lib/sonar_connector/status.rb', line 8 def initialize(config) @status_file = config.status_file load_status end |
Instance Method Details
#[](group) ⇒ Object
28 29 30 |
# File 'lib/sonar_connector/status.rb', line 28 def [](group) status[group] end |
#[]=(group, hash) ⇒ Object
32 33 34 |
# File 'lib/sonar_connector/status.rb', line 32 def []=(group, hash) status[group] = hash end |
#load_status ⇒ Object
13 14 15 |
# File 'lib/sonar_connector/status.rb', line 13 def load_status @status = YAML.load_file(status_file) rescue {} end |
#save_status ⇒ Object
17 18 19 |
# File 'lib/sonar_connector/status.rb', line 17 def save_status File.open(status_file, 'w') { |f| f << status.to_yaml } end |
#set(group, key, value) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/sonar_connector/status.rb', line 21 def set(group, key, value) status[group] = {} unless status[group] status[group][key] = value status[group]['last_updated'] = Time.now.to_s save_status end |