Class: Integral::Storage::FileDecorator

Inherits:
BaseDecorator
  • Object
show all
Defined in:
app/decorators/integral/storage/file_decorator.rb

Overview

Storage File view-level logic

Instance Method Summary collapse

Methods inherited from BaseDecorator

#activity_url, #backend_url, #edit_backend_url, #render_active_block_list

Instance Method Details

#image_url(size: nil, transform: nil, fallback: true) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'app/decorators/integral/storage/file_decorator.rb', line 7

def image_url(size: nil, transform: nil, fallback: true)
  representation = if size
    attachment.representation(Integral.image_transformation_options.merge!(resize_to_limit: Integral.image_sizes[size]))
  elsif transform
    attachment.representation(transform)
  else
    attachment.representation(Integral.image_transformation_options.merge!(resize_to_limit: Integral.image_sizes[:medium]))
  end

  app_url_helpers.url_for(representation)
end

#to_backend_cardHash

Returns the instance as a card.

Returns:

  • (Hash)

    the instance as a card



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/decorators/integral/storage/file_decorator.rb', line 20

def to_backend_card
  attributes = [
    { key: I18n.t('integral.records.attributes.type'), value: attachment.content_type },
    { key: I18n.t('integral.records.attributes.size'), value: h.number_to_human_size(attachment.byte_size) },
    { key: I18n.t('integral.records.attributes.updated_at'), value: I18n.l(updated_at) },
    { key: I18n.t('integral.records.attributes.created_at'), value: I18n.l(created_at) }
  ]

  {
    image: image_url,
    description: description,
    url: backend_url,
    attributes: attributes
  }
end