Sha256: 3d65ba1c8952c1d1cc427bd16690e659e14f91d28815d908e2e6a2c0d652d8c7

Contents?: true

Size: 776 Bytes

Versions: 146

Compression:

Stored size: 776 Bytes

Contents

module Types::Objects::Base
  class AttachmentType < Types::BaseObject
    field :id,          Int,      nil, null: false
    field :filename,    String,   nil, null: false
    field :url,         String,   nil, null: false

    def id
      if object.class.eql?(ActiveStorage::Variant)
        object.blob.id
      else
        object.id
      end
    end

    def filename
      if object.class.eql?(ActiveStorage::Variant)
        object.blob.filename.to_s + "-" + object.variation.transformations[:resize]
      else
        object.filename.to_s
      end
    end

    def url
      if object.class.eql?(ActiveStorage::Variant)
        Rails.application.routes.url_helpers.rails_representation_url(object)
      else
        object.service_url
      end
    end
  end
end

Version data entries

146 entries across 146 versions & 2 rubygems

Version Path
cm-admin-3.0.15 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.14 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.13 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.12 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.11 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.10 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.9 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.8 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.7 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.6 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.5 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.4 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.3 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.2 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.1 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-3.0.0 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-2.4.6 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-2.4.5 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-2.4.4 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb
cm-admin-2.4.3 lib/generators/cm_admin/templates/graphql/objects/base/attachment_type.rb