Class: RackFile

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

Instance Method Summary collapse

Constructor Details

#initialize(temp_file, filename, type, bucket, path) ⇒ RackFile

Returns a new instance of RackFile.



2
3
4
5
6
7
8
# File 'lib/opens3/rack_file.rb', line 2

def initialize(temp_file, filename, type, bucket, path)
	@temp_file = temp_file.path
	@filename = filename
	@type = type
	@bucket = bucket
	@path = path
end

Instance Method Details

#saveObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/opens3/rack_file.rb', line 10

def save
	begin
		key = String.new.random_string
		file_md5 = Digest::MD5.hexdigest(@temp_file)
		folder_name = Digest::MD5.hexdigest("#{@file_md5}-#{Time.now}-#{key}")
		path = "#{@path}/#{@bucket}/#{@filename}"
		FileUtils.mkdir_p(path)
		meta = Hash.new
		meta['type']= @type
		meta['md5'] = file_md5
		meta['filename'] = @filename
    meta = meta.to_yaml
    File.open("#{path}/meta", 'w') do |out|
      out.write(meta)
    end
		FileUtils.mv(@temp_file, "#{path}/content")
	rescue SystemCallError
		false
	end
end