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
- #delete ⇒ Object
-
#initialize(options = {}) ⇒ File
constructor
A new instance of File.
- #open ⇒ Object
- #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
#delete ⇒ Object
37 38 39 |
# File 'lib/star/file.rb', line 37 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 |
#store(tmp_file) ⇒ Object
33 34 35 |
# File 'lib/star/file.rb', line 33 def store(tmp_file) Star.remote? ? store_remote(tmp_file) : store_local(tmp_file) end |
#url ⇒ Object
25 26 27 |
# File 'lib/star/file.rb', line 25 def url "https://#{host}/#{bucket}#{remote_path}?#{url_params}" end |