Class: EbsSnapper::Ebs::TTL

Inherits:
Object
  • Object
show all
Defined in:
lib/ebs_snapper/ebs.rb

Constant Summary collapse

DEFAULT_TTL =

10 days in hours

(86400 * 10) + 3600

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ttl = "10.days") ⇒ TTL

Returns a new instance of TTL.



163
164
165
# File 'lib/ebs_snapper/ebs.rb', line 163

def initialize(ttl = "10.days")
  @cut_off = Time.now.utc.to_i - convert_to_seconds(ttl)
end

Instance Attribute Details

#cut_offObject (readonly)

Returns the value of attribute cut_off.



161
162
163
# File 'lib/ebs_snapper/ebs.rb', line 161

def cut_off
  @cut_off
end

Instance Method Details

#convert_to_seconds(ttl) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/ebs_snapper/ebs.rb', line 172

def convert_to_seconds(ttl)
  ttl_secs = ttl.to_i
  if ttl.kind_of?(String)
    if ttl =~ /\.day/
      # add 1 hr for backup time to extend the save-period.. TODO: maybe more..
      ttl_secs = (ttl.to_i * 86400) + 3600
    elsif ttl =~ /\.hour/
      ttl_secs = ttl.to_i * 3600
    end
  end
  ttl_secs == 0 ? DEFAULT_TTL : ttl_secs
end

#purge?(timestamp) ⇒ Boolean

Returns:

  • (Boolean)


167
168
169
170
# File 'lib/ebs_snapper/ebs.rb', line 167

def purge?(timestamp)
  ts = timestamp.to_i
  ts > 0 && (ts < @cut_off)
end