Class: CoralBackup::Settings
- Inherits:
-
Object
- Object
- CoralBackup::Settings
- Defined in:
- lib/coral_backup/settings.rb
Constant Summary collapse
- INITIAL_SETTINGS =
{ actions: {} }
Instance Method Summary collapse
- #action_data(action_name) ⇒ Object
- #action_names ⇒ Object
- #add(action_name, source, destination, exclusions) ⇒ Object
- #delete(action_name) ⇒ Object
- #exist_action?(action_name) ⇒ Boolean
-
#initialize(filename = "#{Dir.home}/.coral_backup") ⇒ Settings
constructor
A new instance of Settings.
- #update_time(action_name, time) ⇒ Object
Constructor Details
#initialize(filename = "#{Dir.home}/.coral_backup") ⇒ Settings
Returns a new instance of Settings.
9 10 11 12 |
# File 'lib/coral_backup/settings.rb', line 9 def initialize(filename = "#{Dir.home}/.coral_backup") @filename = filename @settings = file_load end |
Instance Method Details
#action_data(action_name) ⇒ Object
14 15 16 17 |
# File 'lib/coral_backup/settings.rb', line 14 def action_data(action_name) raise ArgumentError, "Backup action `#{action_name}' does not exist." unless exist_action?(action_name) @settings[:actions][action_name] end |
#action_names ⇒ Object
19 20 21 |
# File 'lib/coral_backup/settings.rb', line 19 def action_names @settings[:actions].keys end |
#add(action_name, source, destination, exclusions) ⇒ Object
27 28 29 30 31 |
# File 'lib/coral_backup/settings.rb', line 27 def add(action_name, source, destination, exclusions) raise ArgumentError, "Backup action `#{action_name}' already exists." if exist_action?(action_name) @settings[:actions][action_name] = { source: source, destination: destination, exclusions: exclusions } file_dump end |
#delete(action_name) ⇒ Object
33 34 35 36 37 |
# File 'lib/coral_backup/settings.rb', line 33 def delete(action_name) raise ArgumentError, "Backup action `#{action_name}' does not exist." unless exist_action?(action_name) @settings[:actions].delete(action_name) file_dump end |
#exist_action?(action_name) ⇒ Boolean
23 24 25 |
# File 'lib/coral_backup/settings.rb', line 23 def exist_action?(action_name) action_names.include?(action_name) end |
#update_time(action_name, time) ⇒ Object
39 40 41 42 43 |
# File 'lib/coral_backup/settings.rb', line 39 def update_time(action_name, time) raise ArgumentError, "Backup action `#{action_name}' does not exist." unless exist_action?(action_name) @settings[:actions][action_name][:last_run_time] = time.to_s file_dump end |