Class: Dina::File

Inherits:
Object
  • Object
show all
Defined in:
lib/dina/models/object_store/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFile

Returns a new instance of File.



15
16
# File 'lib/dina/models/object_store/file.rb', line 15

def initialize
end

Instance Attribute Details

#file_pathObject

Returns the value of attribute file_path.



3
4
5
# File 'lib/dina/models/object_store/file.rb', line 3

def file_path
  @file_path
end

#groupObject

Returns the value of attribute group.



3
4
5
# File 'lib/dina/models/object_store/file.rb', line 3

def group
  @group
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/dina/models/object_store/file.rb', line 3

def id
  @id
end

#is_derivativeObject

Returns the value of attribute is_derivative.



3
4
5
# File 'lib/dina/models/object_store/file.rb', line 3

def is_derivative
  @is_derivative
end

Class Method Details

.find(group:, id:) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/dina/models/object_store/file.rb', line 5

def self.find(group:, id:)
  obj = self.new
  obj.group = group
  RestClient::Request.execute(
    method: :get,
    headers: { authorization: Dina::Authentication.header },
    url: obj.url + "/#{id}"
  )
end

Instance Method Details

#endpointObject



18
19
20
# File 'lib/dina/models/object_store/file.rb', line 18

def endpoint
  Dina::Authentication.endpoint_url
end

#endpoint_pathObject



22
23
24
# File 'lib/dina/models/object_store/file.rb', line 22

def endpoint_path
  "objectstore-api/"
end

#fileObject



34
35
36
# File 'lib/dina/models/object_store/file.rb', line 34

def file
  ::File.new(file_path)
end

#saveObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dina/models/object_store/file.rb', line 38

def save
  validate_params
  response = RestClient::Request.execute(
    method: :post,
    headers: { authorization: Dina::Authentication.header },
    url: (!is_derivative) ? url : url + "/derivative",
    payload: {
      multipart: true,
      file: file
    }
  )
  json = JSON.parse(response, symbolize_names: true)
  self.id = json[:uuid]
  json
end

#table_nameObject



26
27
28
# File 'lib/dina/models/object_store/file.rb', line 26

def table_name
  "file/#{@group.downcase}"
end

#urlObject



30
31
32
# File 'lib/dina/models/object_store/file.rb', line 30

def url
  endpoint + "/" + endpoint_path + table_name
end