Class: MiteBackup

Inherits:
Object
  • Object
show all
Defined in:
lib/mite-backup.rb,
lib/mite-backup/version.rb

Constant Summary collapse

MAX_CHECKS =
30
SLEEP_BEFORE_EACH_CHECK =

seconds

2
CONFIG_FILE =
File.expand_path('~/.mite-backup.yml')
USER_AGENT =
"mite-backup/#{MiteBackup::VERSION}"
VERSION =
"0.1.3"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ MiteBackup

Returns a new instance of MiteBackup.



14
15
16
17
18
19
20
# File 'lib/mite-backup.rb', line 14

def initialize(options={})
  @options = options
  self.class.clear_config if options["clear_config"]
  @account  = (options["account"]  || config["account"])
  @email    = options["email"]    || config["email"]
  @password = options["password"] || config["password"]
end

Class Method Details

.clear_configObject



43
44
45
# File 'lib/mite-backup.rb', line 43

def self.clear_config
  File.exist?(CONFIG_FILE) && File.delete(CONFIG_FILE)
end

Instance Method Details

#runObject



22
23
24
25
26
27
# File 'lib/mite-backup.rb', line 22

def run
  runnable?
  create
  check
  download
end

#setupObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mite-backup.rb', line 29

def setup
  (config["account"] = @account) || config.delete("account")
  (config["email"] = @email) || config.delete("email")
  (config["password"] = @password) || config.delete("password")

  if config.size == 0
    self.class.clear_config
  else
    File.open(CONFIG_FILE, "w") do |f|
      f.write(YAML::dump(config))
    end
  end
end