Class: Backup

Inherits:
Object
  • Object
show all
Defined in:
lib/bakman/backup.rb

Overview

This class represent one backup of “something”

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filepath) ⇒ Backup

create one instance of Backup with the #filepath



15
16
17
18
19
# File 'lib/bakman/backup.rb', line 15

def initialize(filepath)
  @filepath = filepath
  @date = Date.strptime(filepath[/\d{8}T\d{4}/],'%Y%m%dT%H%M')
  @to_keep = false
end

Instance Attribute Details

#dateObject (readonly)

One backup refers to the #filepath that contains that backup. That file has to be represented by #name_of_something_##date The #date has to be represented this way : %Y%m%dT%H%M



11
12
13
# File 'lib/bakman/backup.rb', line 11

def date
  @date
end

#filepathObject (readonly)

One backup refers to the #filepath that contains that backup. That file has to be represented by #name_of_something_##date The #date has to be represented this way : %Y%m%dT%H%M



11
12
13
# File 'lib/bakman/backup.rb', line 11

def filepath
  @filepath
end

#to_keepObject

Returns the value of attribute to_keep.



12
13
14
# File 'lib/bakman/backup.rb', line 12

def to_keep
  @to_keep
end

Instance Method Details

#delete!Object

delete that backup (you could need that if the backup is too old)



22
23
24
25
# File 'lib/bakman/backup.rb', line 22

def delete!
  puts "#{filepath} deleted."
  File.delete(filepath)
end