Class: DirectWave::Uploader::Versions::Version
- Inherits:
-
Object
- Object
- DirectWave::Uploader::Versions::Version
- Defined in:
- lib/directwave/uploader/versions.rb
Instance Method Summary collapse
- #delete ⇒ Object
- #file ⇒ Object
- #filename ⇒ Object
-
#initialize(uploader, name) ⇒ Version
constructor
A new instance of Version.
- #key ⇒ Object
- #process ⇒ Object
- #retrieve ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(uploader, name) ⇒ Version
Returns a new instance of Version.
6 7 8 9 |
# File 'lib/directwave/uploader/versions.rb', line 6 def initialize(uploader, name) @uploader = uploader @name = name end |
Instance Method Details
#delete ⇒ Object
49 50 51 |
# File 'lib/directwave/uploader/versions.rb', line 49 def delete file.delete if file.exists? end |
#file ⇒ Object
37 38 39 |
# File 'lib/directwave/uploader/versions.rb', line 37 def file @file ||= @uploader.class.s3_directory.objects[key] end |
#filename ⇒ Object
11 12 13 |
# File 'lib/directwave/uploader/versions.rb', line 11 def filename @filename ||= [extract(:guid), [extract(:basename), @name].join("-") << extract(:extname)].join("/") end |
#key ⇒ Object
33 34 35 |
# File 'lib/directwave/uploader/versions.rb', line 33 def key @key ||= File.join([@uploader.store_dir, filename].compact) end |
#process ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/directwave/uploader/versions.rb', line 41 def process @file = nil @filename = nil @url = nil @key = nil @date = nil end |
#retrieve ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/directwave/uploader/versions.rb', line 53 def retrieve Dir.mkdir(@uploader.cache_dir) unless File.exists?(@uploader.cache_dir) @data ||= file.read begin temp_file = Tempfile.new([extract(:basename), extract(:extname)], @uploader.cache_dir) temp_file.binmode temp_file.write(@data) temp_file.flush yield(temp_file) ensure temp_file.close temp_file.unlink end end |
#url ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/directwave/uploader/versions.rb', line 15 def url @url ||= begin uri = if @uploader.s3_access_policy != :public_read file.url_for :get, { expires: @uploader.s3_authentication_timeout } else file.public_url end if @uploader.class.asset_host.present? result = "#{@uploader.class.asset_host}#{uri.path}" result << "?#{uri.query}" if uri.query.present? result else uri.to_s end end end |