Class: EasyBackup::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_backup/specification.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Specification

Returns a new instance of Specification.



4
5
6
7
8
# File 'lib/easy_backup/specification.rb', line 4

def initialize(&block)
  @resources = []
  @storages = []
  instance_eval &block if block_given?
end

Instance Method Details

#into(resource_class, &block) ⇒ Object



16
17
18
19
20
# File 'lib/easy_backup/specification.rb', line 16

def into(resource_class, &block)
  raise "#{resource_class} not respond to save" unless resource_class.instance_methods.include? :save
  @storages << resource_class.new
  @storages.last.instance_eval &block if block_given?
end

#runObject



29
30
31
32
33
# File 'lib/easy_backup/specification.rb', line 29

def run
  @resources.each do |resource|
    resource.send_to *@storages
  end
end

#save(resource_class, &block) ⇒ Object



10
11
12
13
14
# File 'lib/easy_backup/specification.rb', line 10

def save(resource_class, &block)
  raise "#{resource_class} not respond to send_to" unless resource_class.instance_methods.include? :send_to
  @resources << resource_class.new
  @resources.last.instance_eval &block if block_given?
end

#schedule(frequency, *args) ⇒ Object



22
23
24
25
26
27
# File 'lib/easy_backup/specification.rb', line 22

def schedule(frequency, *args)
  EasyBackup.scheduler.send(frequency, *args) do
    EasyBackup.configuration.logger.info "[EasyBackup] Starting at #{Time.now}"
    run
  end
end