Class: Backup::Setup
- Inherits:
-
Object
- Object
- Backup::Setup
- Defined in:
- lib/backup.rb
Instance Attribute Summary collapse
-
#procedure ⇒ Object
Returns the value of attribute procedure.
-
#procedures ⇒ Object
Returns the value of attribute procedures.
-
#trigger ⇒ Object
Returns the value of attribute trigger.
Instance Method Summary collapse
-
#find_triggered_procedure ⇒ Object
Scans through all the backup settings and returns the backup setting that was specified in the “trigger” argument.
-
#initialize(trigger, procedures) ⇒ Setup
constructor
Sets the Trigger and All Available Procedures.
-
#initialize_adapter ⇒ Object
Initializes one of the few adapters and start the backup process.
Constructor Details
#initialize(trigger, procedures) ⇒ Setup
Sets the Trigger and All Available Procedures. Will not find a specific procedure if the “trigger” argument is set to false.
82 83 84 85 86 |
# File 'lib/backup.rb', line 82 def initialize(trigger, procedures) self.trigger = trigger self.procedures = procedures self.procedure = find_triggered_procedure unless trigger.eql?(false) end |
Instance Attribute Details
#procedure ⇒ Object
Returns the value of attribute procedure.
78 79 80 |
# File 'lib/backup.rb', line 78 def procedure @procedure end |
#procedures ⇒ Object
Returns the value of attribute procedures.
78 79 80 |
# File 'lib/backup.rb', line 78 def procedures @procedures end |
#trigger ⇒ Object
Returns the value of attribute trigger.
78 79 80 |
# File 'lib/backup.rb', line 78 def trigger @trigger end |
Instance Method Details
#find_triggered_procedure ⇒ Object
Scans through all the backup settings and returns the backup setting that was specified in the “trigger” argument. If an non-existing trigger is specified, it will raise an error and display all the available triggers.
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/backup.rb', line 106 def find_triggered_procedure procedures.each do |procedure| if procedure.trigger.eql?(trigger) return procedure end end available_triggers = procedures.map {|procedure| "- #{procedure.trigger}\n" } puts "Could not find a backup procedure with the trigger \"#{trigger}\". \nHere's a list of available triggers:\n#{available_triggers}" exit end |
#initialize_adapter ⇒ Object
Initializes one of the few adapters and start the backup process
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/backup.rb', line 89 def initialize_adapter case procedure.adapter_name.to_sym when :mysql then Backup::Adapters::MySQL.new trigger, procedure when :sqlite then Backup::Adapters::SQLite.new trigger, procedure when :postgresql then Backup::Adapters::PostgreSQL.new trigger, procedure when :archive then Backup::Adapters::Archive.new trigger, procedure when :custom then Backup::Adapters::Custom.new trigger, procedure else puts "Unknown Adapter: \"#{procedure.adapter_name}\"." exit end end |