Class: Formstrap::MediaItemView

Inherits:
ViewModel show all
Defined in:
app/models/formstrap/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



17
18
19
# File 'app/models/formstrap/media_item_view.rb', line 17

def attachment
  form.object
end

#content_typeObject



33
34
35
# File 'app/models/formstrap/media_item_view.rb', line 33

def content_type
  attachment.blob&.content_type
end

#filenameObject



29
30
31
# File 'app/models/formstrap/media_item_view.rb', line 29

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

#idObject



25
26
27
# File 'app/models/formstrap/media_item_view.rb', line 25

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

#position_valueObject



21
22
23
# File 'app/models/formstrap/media_item_view.rb', line 21

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

#sizeObject



37
38
39
# File 'app/models/formstrap/media_item_view.rb', line 37

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

#thumbnail_optionsObject



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

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