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.



96
97
98
# File 'lib/ebs_snapper/ebs.rb', line 96

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.



94
95
96
# File 'lib/ebs_snapper/ebs.rb', line 94

def cut_off
  @cut_off
end

Instance Method Details

#convert_to_seconds(ttl) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ebs_snapper/ebs.rb', line 104

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)


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

def purge?(timestamp)
  timestamp < @cut_off
end