Class: Administrate::Field::ActiveStorage

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

Defined Under Namespace

Classes: Engine

Instance Method Summary collapse

Instance Method Details

#attached?Boolean

delegate :attached?, to: :data delegate :attachments, to: :data



104
105
106
# File 'lib/viniBaxter/field/active_storage.rb', line 104

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

#attachmentsObject



108
109
110
# File 'lib/viniBaxter/field/active_storage.rb', line 108

def attachments
  data.attachments if attached?
end

#blob_url(attachment) ⇒ Object



86
87
88
# File 'lib/viniBaxter/field/active_storage.rb', line 86

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

#can_add_attachment?Boolean



90
91
92
# File 'lib/viniBaxter/field/active_storage.rb', line 90

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

#destroy_path(field, attachment) ⇒ Object

this methode is no longer used ness to clean safety



95
96
97
98
99
100
# File 'lib/viniBaxter/field/active_storage.rb', line 95

def destroy_path(field, attachment)
  destroy_path_helper = options.fetch(:destroy_path)
  record_id = field.data.record.id
  attachment_id = attachment.id
  Rails.application.routes.url_helpers.send(destroy_path_helper, {:record_id => record_id, :attachment_id => attachment_id})
end

#destroy_urlObject



60
61
62
# File 'lib/viniBaxter/field/active_storage.rb', line 60

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

#destroyable?Boolean



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

def destroyable?
  options.key?(:destroy_path)
end

#direct?Boolean



36
37
38
# File 'lib/viniBaxter/field/active_storage.rb', line 36

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

#drop_accepted_files?Boolean



56
57
58
# File 'lib/viniBaxter/field/active_storage.rb', line 56

def drop_accepted_files?
  options.fetch(:drop_accepted_files, ".jpeg,.jpg,.png,.gif,.svg")
end

#drop_js?Boolean



40
41
42
# File 'lib/viniBaxter/field/active_storage.rb', line 40

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

#drop_max_file?Boolean



48
49
50
# File 'lib/viniBaxter/field/active_storage.rb', line 48

def drop_max_file?
  options.fetch(:drop_max_file, many? == true ?  10 : 1)
end

#drop_max_file_size?Boolean



52
53
54
# File 'lib/viniBaxter/field/active_storage.rb', line 52

def drop_max_file_size?
  options.fetch(:drop_max_file_size, 10)
end

#index_display_count?Boolean



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

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

#many?Boolean



30
31
32
33
34
# File 'lib/viniBaxter/field/active_storage.rb', line 30

def many?
  # find a way to use instance_of
  # data.class.name == 'ActiveStorage::Attached::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



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

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

#show_drop_js_on_show?Boolean



44
45
46
# File 'lib/viniBaxter/field/active_storage.rb', line 44

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

#show_in_index?Boolean



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

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

#show_preview_sizeObject



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

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

#url(attachment) ⇒ Object



82
83
84
# File 'lib/viniBaxter/field/active_storage.rb', line 82

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

#url_only?Boolean



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

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

#variant(attachment, options) ⇒ Object



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

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