lib/backup/model.rb in backup-3.8.0 vs lib/backup/model.rb in backup-3.9.0

- old
+ new

@@ -23,10 +23,22 @@ all.select {|model| regex =~ model.trigger } else all.select {|model| trigger == model.trigger } end end + + # Allows users to create preconfigured models. + def preconfigure(&block) + @preconfigure ||= block + end + + private + + # used for testing + def reset! + @all = @preconfigure = nil + end end ## # The trigger (stored as a String) is used as an identifier # for initializing the backup process @@ -109,10 +121,11 @@ @archives = [] @storages = [] @notifiers = [] @syncers = [] + instance_eval(&self.class.preconfigure) if self.class.preconfigure instance_eval(&block) if block_given? # trigger all defined databases to generate their #dump_filename # so warnings may be logged if `backup perform --check` is used databases.each {|db| db.send(:dump_filename) } @@ -212,11 +225,12 @@ # to be sent. If the exception is a StandardError, exit_status will be 2. # If the exception is not a StandardError, exit_status will be 3. # # If any exception is raised, any defined +after+ hook will be skipped. def before(&block) - @before ||= block + @before = block if block + @before end ## # Defines a block of code to run after the model's procedures. # @@ -239,10 +253,11 @@ # Raising an exception may elevate the model's exit_status and cause # failure notifications to be sent. If the exception is a StandardError, # the exit_status will be elevated to 2. If the exception is not a # StandardError, the exit_status will be elevated to 3. def after(&block) - @after ||= block + @after = block if block + @after end ## # Performs the backup process #