Class: ActiverecordHoarder::StorageKey

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord_hoarder/storage_key.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_parts, file_extension) ⇒ StorageKey

Returns a new instance of StorageKey.



8
9
10
11
# File 'lib/activerecord_hoarder/storage_key.rb', line 8

def initialize(key_parts, file_extension)
  @key_parts = key_parts
  @file_extension = file_extension
end

Class Method Details

.from_date(date, file_extension = nil) ⇒ Object



3
4
5
6
# File 'lib/activerecord_hoarder/storage_key.rb', line 3

def self.from_date(date, file_extension = nil)
  key_parts = [date.year.to_s, date.month.to_s, date.iso8601]
  new(key_parts, file_extension)
end

Instance Method Details

#to_sObject



13
14
15
16
# File 'lib/activerecord_hoarder/storage_key.rb', line 13

def to_s
  key_without_extension = File.join(@key_parts)
  @file_extension.present? ? key_without_extension + '.' + @file_extension.to_s : key_without_extension
end