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

Returns:

  • (Boolean)


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

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

#attachmentsObject



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

def attachments
  data.attachments if attached?
end

#blob_url(attachment) ⇒ Object



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

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)


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

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

#destroy_path(field, attachment) ⇒ Object

this methode is no longer used ness to clean safety



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

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



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

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

#destroyable?Boolean

Returns:

  • (Boolean)


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

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

#direct?Boolean

Returns:

  • (Boolean)


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

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

#drop_accepted_files?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/viniBaxter/field/active_storage.rb', line 133

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

#drop_js?Boolean

drop js

Returns:

  • (Boolean)


113
114
115
# File 'lib/viniBaxter/field/active_storage.rb', line 113

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

#drop_max_file?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/viniBaxter/field/active_storage.rb', line 125

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

#drop_max_file_size?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/viniBaxter/field/active_storage.rb', line 129

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

#index_display_count?Boolean

Returns:

  • (Boolean)


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

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

#index_display_preview?Boolean

theVariant.service.send(:path_for, theVariant.key) # Absolute path to variant file end

Returns:

  • (Boolean)


20
21
22
# File 'lib/viniBaxter/field/active_storage.rb', line 20

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

#index_preview_sizeObject



24
25
26
# File 'lib/viniBaxter/field/active_storage.rb', line 24

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

#many?Boolean

Returns:

  • (Boolean)


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

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



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

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)


28
29
30
# File 'lib/viniBaxter/field/active_storage.rb', line 28

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

#show_drop_js_on_show?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/viniBaxter/field/active_storage.rb', line 117

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

#show_in_index?Boolean

Returns:

  • (Boolean)


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

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

#show_preview_sizeObject



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

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

#sweety_show_drop_js_on_show?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/viniBaxter/field/active_storage.rb', line 121

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

#url(attachment) ⇒ Object



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

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

#url_only?Boolean

Returns:

  • (Boolean)


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

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

#variant(attachment, options) ⇒ Object



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

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