Class: Star::File

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @name = options.fetch :name, 'attachment'
  @content_type = options.fetch :content_type, 'application/octet-stream'
  @folder = options.fetch :folder, 'attachments'
end

Instance Attribute Details

#content_typeObject (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

#openObject



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

#pathObject



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

#urlObject



25
26
27
# File 'lib/star/file.rb', line 25

def url
  "https://#{host}/#{bucket}#{remote_path}?#{url_params}"
end