Class: PoringBackup::Setting

Inherits:
Object
  • Object
show all
Includes:
PoringBackup::Settings::Callback
Defined in:
lib/poring_backup/setting.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PoringBackup::Settings::Callback

#after, #before

Constructor Details

#initialize(name = nil, &block) ⇒ Setting

Returns a new instance of Setting.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/poring_backup/setting.rb', line 13

def initialize name=nil, &block
  @app_name = name
  @created_at = Time.now.strftime("%Y.%m.%d.%H.%M.%S")
  @before_actions = []
  @after_actions = []
  @dir = 'poring_backups'
  @tmp_dir = "tmp/poring_backups"
  @databases = []
  @storages = []
  @notifiers = []
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#after_actionsObject (readonly)

Returns the value of attribute after_actions.



8
9
10
# File 'lib/poring_backup/setting.rb', line 8

def after_actions
  @after_actions
end

#app_nameObject (readonly)

Returns the value of attribute app_name.



7
8
9
# File 'lib/poring_backup/setting.rb', line 7

def app_name
  @app_name
end

#before_actionsObject (readonly)

Returns the value of attribute before_actions.



8
9
10
# File 'lib/poring_backup/setting.rb', line 8

def before_actions
  @before_actions
end

#created_atObject (readonly)

Returns the value of attribute created_at.



11
12
13
# File 'lib/poring_backup/setting.rb', line 11

def created_at
  @created_at
end

#databasesObject (readonly)

Returns the value of attribute databases.



10
11
12
# File 'lib/poring_backup/setting.rb', line 10

def databases
  @databases
end

#dirObject (readonly)

Returns the value of attribute dir.



9
10
11
# File 'lib/poring_backup/setting.rb', line 9

def dir
  @dir
end

#notifiersObject (readonly)

Returns the value of attribute notifiers.



10
11
12
# File 'lib/poring_backup/setting.rb', line 10

def notifiers
  @notifiers
end

#storagesObject (readonly)

Returns the value of attribute storages.



10
11
12
# File 'lib/poring_backup/setting.rb', line 10

def storages
  @storages
end

#tmp_dirObject (readonly)

Returns the value of attribute tmp_dir.



9
10
11
# File 'lib/poring_backup/setting.rb', line 9

def tmp_dir
  @tmp_dir
end

Instance Method Details

#clear_tmp!Object



49
50
51
52
# File 'lib/poring_backup/setting.rb', line 49

def clear_tmp!
  FileUtils.rm_rf(tmp_dir)
  PoringBackup.logger.debug "clear tmp directory"
end

#database(model, &block) ⇒ Object



26
27
28
# File 'lib/poring_backup/setting.rb', line 26

def database model, &block
  @databases << class_from_scope(Databases, model).new(self, &block)
end

#notifier(model, &block) ⇒ Object



34
35
36
# File 'lib/poring_backup/setting.rb', line 34

def notifier model, &block
  @notifiers << class_from_scope(Notifiers, model).new(self, &block)
end

#perform!Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/poring_backup/setting.rb', line 38

def perform!
  PoringBackup.logger.info "PoringBackup Start..."
  before_backup
  backup!
  store!
  clear_tmp!
  after_backup
  notify!
  PoringBackup.logger.info "PoringBackup Done"
end

#store_with(model, &block) ⇒ Object



30
31
32
# File 'lib/poring_backup/setting.rb', line 30

def store_with model, &block
  @storages << class_from_scope(Storages, model).new(self, &block)
end