Class: PruneCloudfilesDbBackups::Backup

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Backup

Creates a new instance of backup with a grouped set of related files

Parameters:

  • options (Hash) (defaults to: {})

    in the form of a hash

Options Hash (options):

  • :objects (Set)
  • :name (String)

    is optional and will be gleaned from objects if not specified

  • :date (DateTime)

    is optional and will be gleaned from objects if not specified

  • :monthly (Boolean)
  • :weekly (Boolean)
  • :daily (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 19

def initialize(options = {})
  @objects = options[:objects] || (raise ArgumentError, 'Objects not specified')
  @name = options[:name] || self.class.parse_for_name(@objects)
  @datetime = options[:datetime] || self.class.parse_for_datetime(@objects)
  @monthly = options[:monthly]
  @weekly = options[:weekly]
  @daily = options[:daily]
end

Instance Attribute Details

#dailyObject (readonly)

Returns the value of attribute daily.



5
6
7
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 5

def daily
  @daily
end

#datetimeObject (readonly)

Returns the value of attribute datetime.



6
7
8
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 6

def datetime
  @datetime
end

#monthlyObject (readonly)

Returns the value of attribute monthly.



5
6
7
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 5

def monthly
  @monthly
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 8

def name
  @name
end

#objectsObject (readonly)

Returns the value of attribute objects.



7
8
9
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 7

def objects
  @objects
end

#weeklyObject (readonly)

Returns the value of attribute weekly.



5
6
7
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 5

def weekly
  @weekly
end

Class Method Details

.parse_for_datetime(objects) ⇒ Object

Parameters:

  • objects (Enumerable)


34
35
36
37
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 34

def self.parse_for_datetime(objects)
  str_date = objects.first[/\d{14}/]
  DateTime.strptime(str_date, '%Y%m%d%H%M%S')
end

.parse_for_name(objects) ⇒ Object

Parameters:

  • objects (Enumerable)


29
30
31
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 29

def self.parse_for_name(objects)
  objects.first[/(^.+\.pgdump).*/, 1]
end

Instance Method Details

#==(other_backup) ⇒ Object

Parameters:



48
49
50
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 48

def ==(other_backup)
  self.objects == other_backup.objects
end

#dbnameObject



39
40
41
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 39

def dbname
  @name[/(.+)-\d{14}/, 1]
end

#deletable?Boolean

Returns:

  • (Boolean)


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

def deletable?
  !(@daily|@weekly|@monthly)
end

#to_sObject

noinspection RubyResolve



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/prune_cloudfiles_db_backups/backup.rb', line 53

def to_s
  mwd = '['
  mwd << 'd' if @daily
  mwd << '-' unless @daily
  mwd << 'w' if @weekly
  mwd << '-' unless @weekly
  mwd << 'm' if @monthly
  mwd << '-' unless @monthly
  mwd << ']'

  "#{mwd} #{dbname} #{@datetime.rfc822} (#{objects.size} item#{'s' if @objects.size > 1})"
end