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.



101
102
103
# File 'lib/ebs_snapper/ebs.rb', line 101

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.



99
100
101
# File 'lib/ebs_snapper/ebs.rb', line 99

def cut_off
  @cut_off
end

Instance Method Details

#convert_to_seconds(ttl) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/ebs_snapper/ebs.rb', line 110

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)


105
106
107
108
# File 'lib/ebs_snapper/ebs.rb', line 105

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