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(&block) ⇒ Setting

Returns a new instance of Setting.



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

def initialize &block
  @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 = []
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#after_actionsObject (readonly)

Returns the value of attribute after_actions.



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

def after_actions
  @after_actions
end

#before_actionsObject (readonly)

Returns the value of attribute before_actions.



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

def before_actions
  @before_actions
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#databasesObject (readonly)

Returns the value of attribute databases.



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

def databases
  @databases
end

#dirObject (readonly)

Returns the value of attribute dir.



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

def dir
  @dir
end

#storagesObject (readonly)

Returns the value of attribute storages.



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

def storages
  @storages
end

#tmp_dirObject (readonly)

Returns the value of attribute tmp_dir.



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

def tmp_dir
  @tmp_dir
end

Instance Method Details

#clear_tmp!Object



41
42
43
44
# File 'lib/poring_backup/setting.rb', line 41

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

#database(model, &block) ⇒ Object



23
24
25
# File 'lib/poring_backup/setting.rb', line 23

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

#perform!Object



31
32
33
34
35
36
37
38
39
# File 'lib/poring_backup/setting.rb', line 31

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

#store_with(model, &block) ⇒ Object



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

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