Class: CoralBackup::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/coral_backup/settings.rb

Constant Summary collapse

INITIAL_SETTINGS =
{
  actions: {}
}

Instance Method Summary collapse

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

Raises:

  • (ArgumentError)


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_namesObject



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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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

Returns:

  • (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

Raises:

  • (ArgumentError)


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