Class: CloudAlign::File

Inherits:
BaseEntity show all
Defined in:
lib/cloudalign/file.rb

Instance Attribute Summary collapse

Attributes inherited from BaseEntity

#created_at, #id, #updated_at

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseEntity

#initialize

Constructor Details

This class inherits a constructor from CloudAlign::BaseEntity

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/cloudalign/file.rb', line 3

def name
  @name
end

#readyObject

Returns the value of attribute ready.



3
4
5
# File 'lib/cloudalign/file.rb', line 3

def ready
  @ready
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/cloudalign/file.rb', line 3

def size
  @size
end

#storage_pathObject

Returns the value of attribute storage_path.



3
4
5
# File 'lib/cloudalign/file.rb', line 3

def storage_path
  @storage_path
end

Class Method Details

.find(artifact_id, id) ⇒ Object



22
23
24
# File 'lib/cloudalign/file.rb', line 22

def find(artifact_id, id)
  File.new(Client.get_json("/artifacts/#{artifact_id}/files/#{id}"))
end

.find_by_artifact(artifact_id) ⇒ Object



26
27
28
29
30
# File 'lib/cloudalign/file.rb', line 26

def find_by_artifact(artifact_id)
  Client.get_json("/artifacts/#{artifact_id}/files").map do |row|
    File.new(row)
  end
end

Instance Method Details

#download(output_path = nil) ⇒ Object



5
6
7
8
9
# File 'lib/cloudalign/file.rb', line 5

def download(output_path = nil)
  output_path = self.file_name if output_path.nil?
  download_info = Client.get_json("/artifacts/#{@artifact_id}/files/#{@id}/download")
  Client.get_file(download_info["download_url"], output_path)
end

#file_nameObject



11
12
13
# File 'lib/cloudalign/file.rb', line 11

def file_name
  ::File.basename(@storage_path)
end

#statusObject



15
16
17
18
# File 'lib/cloudalign/file.rb', line 15

def status
  statuses = %w(READY BUILDING UPLOADING)
  (@status >= 0 && @status < statuses.length) ? statuses[@status] : @status
end