Class: Vert::Concerns::DocumentStoreable::DocumentAttachment

Inherits:
Object
  • Object
show all
Defined in:
lib/vert/concerns/document_storeable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object_id:, resource:, owner:) ⇒ DocumentAttachment

Returns a new instance of DocumentAttachment.



137
138
139
140
141
# File 'lib/vert/concerns/document_storeable.rb', line 137

def initialize(object_id:, resource:, owner:)
  @storage_object_id = object_id
  @resource = resource
  @owner = owner
end

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



135
136
137
# File 'lib/vert/concerns/document_storeable.rb', line 135

def owner
  @owner
end

#resourceObject (readonly)

Returns the value of attribute resource.



135
136
137
# File 'lib/vert/concerns/document_storeable.rb', line 135

def resource
  @resource
end

#storage_object_idObject (readonly)

Returns the value of attribute storage_object_id.



135
136
137
# File 'lib/vert/concerns/document_storeable.rb', line 135

def storage_object_id
  @storage_object_id
end

Instance Method Details

#attached?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/vert/concerns/document_storeable.rb', line 169

def attached?
  storage_object_id.present?
end

#byte_sizeObject



165
166
167
# File 'lib/vert/concerns/document_storeable.rb', line 165

def byte_size
  details&.dig(:size)
end

#content_typeObject



161
162
163
# File 'lib/vert/concerns/document_storeable.rb', line 161

def content_type
  details&.dig(:mime_type)
end

#detailsObject



152
153
154
155
# File 'lib/vert/concerns/document_storeable.rb', line 152

def details
  result = client.object(storage_object_id)
  result[:success] ? result[:data] : nil
end

#downloadObject



148
149
150
# File 'lib/vert/concerns/document_storeable.rb', line 148

def download
  client.download(object_id: storage_object_id)
end

#filenameObject



157
158
159
# File 'lib/vert/concerns/document_storeable.rb', line 157

def filename
  details&.dig(:original_filename)
end

#url(disposition: "inline", expires_in: 3600) ⇒ Object



143
144
145
146
# File 'lib/vert/concerns/document_storeable.rb', line 143

def url(disposition: "inline", expires_in: 3600)
  result = client.download_url(object_id: storage_object_id, disposition: disposition, expires_in: expires_in)
  result[:success] ? result[:data][:url] : nil
end