Class: Headmin::Form::MediaItemView

Inherits:
ViewModel
  • Object
show all
Defined in:
app/models/headmin/form/media_item_view.rb

Instance Method Summary collapse

Methods inherited from ViewModel

#attributes, #initialize, #to_hash

Constructor Details

This class inherits a constructor from ViewModel

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ViewModel

Instance Method Details

#attachmentObject



18
19
20
# File 'app/models/headmin/form/media_item_view.rb', line 18

def attachment
  form.object
end

#content_typeObject



34
35
36
# File 'app/models/headmin/form/media_item_view.rb', line 34

def content_type
  attachment.blob&.content_type
end

#filenameObject



30
31
32
# File 'app/models/headmin/form/media_item_view.rb', line 30

def filename
  attachment.blob&.filename&.to_s
end

#idObject



26
27
28
# File 'app/models/headmin/form/media_item_view.rb', line 26

def id
  attachment.blob ? attachment.blob.id : "$1"
end

#position_valueObject



22
23
24
# File 'app/models/headmin/form/media_item_view.rb', line 22

def position_value
  attachment.new_record? ? nil : attachment.position
end

#sizeObject



38
39
40
# File 'app/models/headmin/form/media_item_view.rb', line 38

def size
  number_to_human_size(attachment.blob&.byte_size || 0)
end

#thumbnail_optionsObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/models/headmin/form/media_item_view.rb', line 6

def thumbnail_options
  options = {
    file: attachment
  }

  # Don't pass width or height if it was not defined
  options = options.merge(width: width) if is_defined?(:width)
  options = options.merge(height: height) if is_defined?(:height)

  options
end