Class: Integral::Storage::File

Inherits:
ApplicationRecord show all
Defined in:
app/models/integral/storage/file.rb

Overview

Represents a file uploaded by a user

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

available_statuses

Class Method Details

.integral_backend_create_menu_itemHash

Returns hash representing the class, used to render within the create menu.

Returns:

  • (Hash)

    hash representing the class, used to render within the create menu



50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/integral/storage/file.rb', line 50

def self.integral_backend_create_menu_item
  {
    icon: integral_icon,
    order: integral_options.dig(:backend_create_menu, :order),
    label: I18n.t('integral.actions.upload'),
    url: url_helpers.send("new_backend_#{model_name.singular_route_key}_url"),
    # authorize: proc { policy(self).index? }, can't use this as self is in wrong context
    authorize_class: self,
    authorize_action: :new,
  }
end

.integral_backend_main_menu_itemHash

Returns hash representing the class, used to render within the main menu.

Returns:

  • (Hash)

    hash representing the class, used to render within the main menu



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/integral/storage/file.rb', line 32

def self.integral_backend_main_menu_item
  {
    icon: integral_icon,
    order: integral_options.dig(:backend_main_menu, :order),
    label: I18n.t('integral.navigation.storage_files'),
    url: url_helpers.send("backend_#{model_name.route_key}_url"),
    # authorize: proc { policy(self).index? }, can't use this as self is in wrong context
    authorize_class: self,
    authorize_action: :index,
    list_items: [
      { label: I18n.t('integral.navigation.dashboard'), url: url_helpers.send("backend_#{model_name.route_key}_url"), authorize_class: self, authorize_action: :index },
      { label: I18n.t('integral.actions.upload'), url: url_helpers.send("new_backend_#{model_name.singular_route_key}_url"), authorize_class: self, authorize_action: :new },
      { label: I18n.t('integral.navigation.list'), url: url_helpers.send("list_backend_#{model_name.route_key}_url"), authorize_class: self, authorize_action: :list },
    ]
  }
end

Instance Method Details

#eagerly_process_image_variantsObject



73
74
75
76
77
# File 'app/models/integral/storage/file.rb', line 73

def eagerly_process_image_variants
  if attachment.attached? && attachment.image?
    ProcessImageVariantsJob.perform_later(self)
  end
end

#to_list_itemHash

Returns the instance as a list item.

Returns:

  • (Hash)

    the instance as a list item



63
64
65
66
67
68
69
70
71
# File 'app/models/integral/storage/file.rb', line 63

def to_list_item
  {
    id: id,
    title: title,
    subtitle: attachment.byte_size,
    description: description,
    image: attachment
  }
end