Class: ListCloudFiles

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

Overview

ListCloudFiles

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.aws_access_key_idObject

Returns the value of attribute aws_access_key_id.



5
6
7
# File 'lib/list_cloud_files.rb', line 5

def aws_access_key_id
  @aws_access_key_id
end

.aws_secret_access_keyObject

Returns the value of attribute aws_secret_access_key.



5
6
7
# File 'lib/list_cloud_files.rb', line 5

def aws_secret_access_key
  @aws_secret_access_key
end

.cache_expires_inObject

Returns the value of attribute cache_expires_in.



5
6
7
# File 'lib/list_cloud_files.rb', line 5

def cache_expires_in
  @cache_expires_in
end

Class Method Details

.get_files_for_bucket(bucket_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/list_cloud_files.rb', line 7

def get_files_for_bucket(bucket_name)
  Rails.cache.fetch(bucket_name, :expires_in => (@cache_expires_in || 1.day)) do
    storage = Fog::Storage.new(:provider => 'AWS', :aws_access_key_id => @aws_access_key_id, :aws_secret_access_key => @aws_secret_access_key)
    directory = storage.directories.get(bucket_name)
    files = directory.files

    #read the metadata file and build a hash of info for each file
     = {}
    if directory.files.get('_metadata.txt')
      directory.files.get('_metadata.txt').body.split("\n").each do |line|
        file_name, description = line.split('|')
        [file_name] = { :description => description }
      end
    end

    file_names = []
    files.reject{|f| f.key == '_metadata.txt'}.each do |file|
      file_name = file.key
      file_names << file_name
      name, extension = file_name.rpartition('.')[0], file_name.rpartition('.')[2]
      pretty_name = name.gsub('_', ' ')
      [file_name].merge!({
        :pretty_name => pretty_name,
        :extension => extension,
        :public_url => file.public_url
      })
    end

    #returning our hash of info
    {:file_names => file_names, :file_metadata => }
  end
end

.get_html_for_files(cloud_files) ⇒ Object



40
41
42
# File 'lib/list_cloud_files.rb', line 40

def get_html_for_files(cloud_files)
  #must be passed a hash with :file_names => array of filenames, :file_metadata => hash of metadata keyed on filename
end