Class: Star::File
- Inherits:
-
Object
- Object
- Star::File
- Defined in:
- lib/star/file.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
Instance Method Summary collapse
- #copy_from(source) ⇒ Object
- #delete ⇒ Object
-
#initialize(options = {}) ⇒ File
constructor
A new instance of File.
- #open ⇒ Object
- #path ⇒ Object
- #remote_path ⇒ Object
- #store(tmp_file) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ File
Returns a new instance of File.
11 12 13 14 15 |
# File 'lib/star/file.rb', line 11 def initialize( = {}) @name = .fetch :name, 'attachment' @content_type = .fetch :content_type, 'application/octet-stream' @folder = .fetch :folder, 'attachments' end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
9 10 11 |
# File 'lib/star/file.rb', line 9 def content_type @content_type end |
Instance Method Details
#copy_from(source) ⇒ Object
45 46 47 |
# File 'lib/star/file.rb', line 45 def copy_from(source) Star.remote? ? copy_from_remote(source) : copy_from_local(source) end |
#delete ⇒ Object
41 42 43 |
# File 'lib/star/file.rb', line 41 def delete Star.remote? ? delete_remote : delete_local end |
#open ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/star/file.rb', line 17 def open Tempfile.open 'tmp_file' do |tmp_file| yield tmp_file tmp_file.flush store tmp_file end end |
#path ⇒ Object
29 30 31 |
# File 'lib/star/file.rb', line 29 def path [Star.configuration.location, @folder, @name].compact.join('/') end |
#remote_path ⇒ Object
49 50 51 |
# File 'lib/star/file.rb', line 49 def remote_path URI.escape path end |
#store(tmp_file) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/star/file.rb', line 33 def store(tmp_file) if Star.remote? retry_on_error {store_remote tmp_file} else store_local(tmp_file) end end |
#url ⇒ Object
25 26 27 |
# File 'lib/star/file.rb', line 25 def url "https://#{host}/#{bucket}#{remote_path}?#{url_params}" end |