Class: Avo::Fields::Common::Files::ViewType::GridItemComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Avo::Fields::Common::Files::ViewType::GridItemComponent
- Defined in:
- app/components/avo/fields/common/files/view_type/grid_item_component.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#field ⇒ Object
readonly
Returns the value of attribute field.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #file ⇒ Object
- #id ⇒ Object
-
#initialize(field:, resource:, file: nil, extra_classes: nil) ⇒ GridItemComponent
constructor
A new instance of GridItemComponent.
- #is_audio? ⇒ Boolean
- #is_image? ⇒ Boolean
- #is_video? ⇒ Boolean
-
#record_persisted? ⇒ Boolean
If record is not persistent blob is automatically destroyed otherwise it can be “lost” on storage.
- #render? ⇒ Boolean
Constructor Details
#initialize(field:, resource:, file: nil, extra_classes: nil) ⇒ GridItemComponent
Returns a new instance of GridItemComponent.
6 7 8 9 10 11 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 6 def initialize(field:, resource:, file: nil, extra_classes: nil) @file = file @field = field @resource = resource @extra_classes = extra_classes end |
Instance Attribute Details
#field ⇒ Object (readonly)
Returns the value of attribute field.
4 5 6 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 4 def field @field end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
4 5 6 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 4 def resource @resource end |
Instance Method Details
#file ⇒ Object
17 18 19 20 21 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 17 def file @file || field.value. rescue nil end |
#id ⇒ Object
13 14 15 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 13 def id field.id end |
#is_audio? ⇒ Boolean
29 30 31 32 33 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 29 def is_audio? file.audio? || field.is_audio rescue false end |
#is_image? ⇒ Boolean
23 24 25 26 27 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 23 def is_image? file.image? || field.is_image rescue false end |
#is_video? ⇒ Boolean
35 36 37 38 39 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 35 def is_video? file.video? || field.is_video rescue false end |
#record_persisted? ⇒ Boolean
If record is not persistent blob is automatically destroyed otherwise it can be “lost” on storage
46 47 48 49 50 51 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 46 def record_persisted? return true if @resource.record.persisted? ActiveStorage::Blob.destroy(file.blob_id) if file.blob_id.present? false end |
#render? ⇒ Boolean
41 42 43 |
# File 'app/components/avo/fields/common/files/view_type/grid_item_component.rb', line 41 def render? record_persisted? end |