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)


81
82
83
# File 'lib/administrate/field/active_storage.rb', line 81

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

#attachmentsObject



85
86
87
# File 'lib/administrate/field/active_storage.rb', line 85

def attachments
  many? ? data.attachments : [data.attachment] if attached?
end

#blob_url(attachment) ⇒ Object



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

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)


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

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

#destroy_urlObject



51
52
53
# File 'lib/administrate/field/active_storage.rb', line 51

def destroy_url
  options.fetch(:destroy_url, nil)
end

#direct?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/administrate/field/active_storage.rb', line 47

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

#index_display_count?Boolean

Returns:

  • (Boolean)


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

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

#index_display_preview?Boolean

Returns:

  • (Boolean)


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

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

#index_preview_only?Boolean

Returns:

  • (Boolean)


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

def index_preview_only?
  options.fetch(:index_preview_only, false)
end

#index_preview_sizeObject



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

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

#index_preview_variantObject



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

def index_preview_variant
  options.fetch(:index_preview_variant, nil)
end

#many?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/administrate/field/active_storage.rb', line 43

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



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

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)


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

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

#show_preview_sizeObject



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

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

#show_preview_variantObject



39
40
41
# File 'lib/administrate/field/active_storage.rb', line 39

def show_preview_variant
  options.fetch(:show_preview_variant, nil)
end

#url(attachment) ⇒ Object



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

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

#variant(attachment, options) ⇒ Object



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

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