Class: ThinOutBackups::Command::Bucket
- Inherits:
-
Object
- Object
- ThinOutBackups::Command::Bucket
- Defined in:
- lib/thin_out_backups.rb
Overview
Constant Summary collapse
- @@quota_format =
%r[(\d+|\*)(/\d+)?]
Instance Attribute Summary collapse
-
#keepers ⇒ Object
readonly
Returns the value of attribute keepers.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#quota ⇒ Object
readonly
Returns the value of attribute quota.
Instance Method Summary collapse
-
#initialize(parent, name, quota) ⇒ Bucket
constructor
A new instance of Bucket.
- #keep(keeper) ⇒ Object
- #keep_all? ⇒ Boolean
- #satisfied? ⇒ Boolean
- #start_time ⇒ Object
- #still_need ⇒ Object
- #unit ⇒ Object
Constructor Details
#initialize(parent, name, quota) ⇒ Bucket
Returns a new instance of Bucket.
60 61 62 63 64 65 66 67 68 |
# File 'lib/thin_out_backups.rb', line 60 def initialize(parent, name, quota) @parent = parent @name = name ( raise "Invalid quota '#{quota}'" unless quota.is_a?(Fixnum) || quota =~ @@quota_format @quota = quota ) @keepers = [] end |
Instance Attribute Details
#keepers ⇒ Object (readonly)
Returns the value of attribute keepers.
57 58 59 |
# File 'lib/thin_out_backups.rb', line 57 def keepers @keepers end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
57 58 59 |
# File 'lib/thin_out_backups.rb', line 57 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
57 58 59 |
# File 'lib/thin_out_backups.rb', line 57 def parent @parent end |
#quota ⇒ Object (readonly)
Returns the value of attribute quota.
57 58 59 |
# File 'lib/thin_out_backups.rb', line 57 def quota @quota end |
Instance Method Details
#keep(keeper) ⇒ Object
108 109 110 |
# File 'lib/thin_out_backups.rb', line 108 def keep(keeper) @keepers << keeper end |
#keep_all? ⇒ Boolean
120 |
# File 'lib/thin_out_backups.rb', line 120 def keep_all?; quota =~ /\*/ end |
#satisfied? ⇒ Boolean
122 123 124 125 126 127 128 |
# File 'lib/thin_out_backups.rb', line 122 def satisfied? if keep_all? false # it has insatiable hunger for keepers that can never be satisfied else still_need == 0 end end |
#start_time ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/thin_out_backups.rb', line 81 def start_time start_time = parent.now.dup if parent.align_at_beginning_of_time_interval beginning_of_interval = case unit when :minutes start_time.change(:sec => 0) when :hours start_time.change(:min => 0) when :days start_time.change(:hour => 0) when :weeks start_time.beginning_of_week(:sunday) when :months start_time.change( :day => 1, :hour => 0) when :years start_time.change(:month => 1, :day => 1, :hour => 0) else raise "unexpected unit #{unit}" end # We actually want to use the *next* interval (in the future) as our start_time because we will be using this as our max and going backwards in time... beginning_of_interval.shift(1, unit) else start_time end end |
#still_need ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/thin_out_backups.rb', line 112 def still_need if keep_all? 1 # it has insatiable hunger for keepers that can never be satisfied ... always just 1 more ... else @quota - @keepers.size end end |
#unit ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/thin_out_backups.rb', line 70 def unit { :minutely => :minutes, :hourly => :hours, :daily => :days, :weekly => :weeks, :monthly => :months, :yearly => :years, }[@name.to_sym] end |