make model extendable #191

Closed
wants to merge 1 commit into
from
Jump to file
+21 −2
Split
View
@@ -5,6 +5,10 @@ class Model
include Backup::CLI
##
+ # The parent is used to extend a config
+ attr_accessor :parent
+
+ ##
# The trigger is used as an identifier for
# initializing the backup process
attr_accessor :trigger
@@ -94,10 +98,11 @@ def tmp_path
# configuration for the model, it will append the newly created "model" instance
# to the @all class variable (Array) so it can be accessed by Backup::Finder
# and any other location
- def initialize(trigger, label, &block)
+ def initialize(trigger, label, parent, &block)
@trigger = trigger
@label = label
@time = TIME
+ @parent = parent
@databases = Array.new
@archives = Array.new
@@ -106,8 +111,22 @@ def initialize(trigger, label, &block)
@storages = Array.new
@notifiers = Array.new
@syncers = Array.new
-
+
instance_eval(&block)
+
+ Backup::Model.all.each {
+ |model|
+ if model.trigger == @parent
+ @databases = self.databases | model.databases
+ @archives = self.archives | model.archives
+ @encryptors = self.encryptors | model.encryptors
+ @compressors = self.compressors | model.compressors
+ @storages = self.storages | model.storages
+ @notifiers = self.notifiers | model.notifiers
+ @syncers = self.syncers | model.syncers
+ end
+ }
+
Backup::Model.all << self
end