Class: Types::Objects::Base::AttachmentType
- Inherits:
-
BaseObject
- Object
- BaseObject
- Types::Objects::Base::AttachmentType
- Defined in:
- app/graphql/types/objects/base/attachment_type.rb
Instance Method Summary collapse
Instance Method Details
#base64 ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'app/graphql/types/objects/base/attachment_type.rb', line 34 def base64 data = if object.class.eql?(ActiveStorage::Variant) Base64.strict_encode64(object.blob.download) else Base64.strict_encode64(object.download) end "data:#{object.content_type};base64,#{data}" end |
#filename ⇒ Object
16 17 18 19 20 21 22 |
# File 'app/graphql/types/objects/base/attachment_type.rb', line 16 def filename if object.class.eql?(ActiveStorage::Variant) object.blob.filename.to_s + "-" + object.variation.transformations[:resize] else object.filename.to_s end end |
#id ⇒ Object
8 9 10 11 12 13 14 |
# File 'app/graphql/types/objects/base/attachment_type.rb', line 8 def id if object.class.eql?(ActiveStorage::Variant) object.blob.id else object.id end end |
#url ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/graphql/types/objects/base/attachment_type.rb', line 24 def url if object.class.eql?(ActiveStorage::Variant) Rails.application.routes.url_helpers.rails_representation_url(object) elsif defined?(object.service_url) object.service_url else object.url end end |