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

#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

#deleteObject



41
42
43
# File 'lib/star/file.rb', line 41

def delete
  Star.remote? ? delete_remote : delete_local
end

#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

#remote_pathObject



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

#urlObject



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

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