Class: Administrate::Field::ActiveStorage

Inherits:
Base
  • Object
show all
Defined in:
lib/administrate/field/active_storage.rb

Defined Under Namespace

Classes: Engine

Instance Method Summary collapse

Instance Method Details

#attached?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/administrate/field/active_storage.rb', line 74

def attached?
  data.present? && data.attached?
end

#attachmentsObject



78
79
80
# File 'lib/administrate/field/active_storage.rb', line 78

def attachments
  data.attachments if attached?
end

#blob_url(attachment) ⇒ Object



66
67
68
# File 'lib/administrate/field/active_storage.rb', line 66

def blob_url(attachment)
  Rails.application.routes.url_helpers.rails_blob_path(attachment, disposition: :attachment, only_path: true)
end

#can_add_attachment?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/administrate/field/active_storage.rb', line 70

def can_add_attachment?
  many? || attachments.blank?
end

#destroy_urlObject



38
39
40
41
42
43
44
45
46
# File 'lib/administrate/field/active_storage.rb', line 38

def destroy_url
  options.fetch(:destroy_url) do
    proc do |namespace, record, attachment|
      options = [attachment.name, namespace, record]
      options << { attachment_id: attachment.id } if many?
      options
    end
  end
end

#direct?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/administrate/field/active_storage.rb', line 34

def direct?
  options.fetch(:direct_upload, false)
end

#index_display_count?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/administrate/field/active_storage.rb', line 18

def index_display_count?
  options.fetch(:index_display_count) { attachments.present? && attachments.count != 1 }
end

#index_display_preview?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/administrate/field/active_storage.rb', line 10

def index_display_preview?
  options.fetch(:index_display_preview, true)
end

#index_preview_sizeObject



14
15
16
# File 'lib/administrate/field/active_storage.rb', line 14

def index_preview_size
  options.fetch(:index_preview_size, [150, 150])
end

#many?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/administrate/field/active_storage.rb', line 30

def many?
  data.is_a? ::ActiveStorage::Attached::Many
end

#preview(attachment, options) ⇒ Object

work around since calling data.preview(options) returns “/images/<ActiveStorage::Preview>” which isnt the url



54
55
56
# File 'lib/administrate/field/active_storage.rb', line 54

def preview(attachment, options)
  Rails.application.routes.url_helpers.rails_representation_path(attachment.preview(options), only_path: true)
end

#show_display_preview?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/administrate/field/active_storage.rb', line 22

def show_display_preview?
  options.fetch(:show_display_preview, true)
end

#show_preview_sizeObject



26
27
28
# File 'lib/administrate/field/active_storage.rb', line 26

def show_preview_size
  options.fetch(:show_preview_size, [800, 800])
end

#url(attachment) ⇒ Object



62
63
64
# File 'lib/administrate/field/active_storage.rb', line 62

def url(attachment)
  Rails.application.routes.url_helpers.rails_blob_path(attachment, only_path: true)
end

#variant(attachment, options) ⇒ Object



58
59
60
# File 'lib/administrate/field/active_storage.rb', line 58

def variant(attachment, options)
  Rails.application.routes.url_helpers.rails_representation_path(attachment.variant(combine_options: options), only_path: true)
end