Class: FlexiAdmin::Components::Resources::GridViewComponent::Element

Inherits:
Struct
  • Object
show all
Includes:
Helpers::UrlHelper
Defined in:
lib/flexi_admin/components/resources/grid_view_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributeObject

Returns the value of attribute attribute

Returns:

  • (Object)

    the current value of attribute



11
12
13
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 11

def attribute
  @attribute
end

#main_appObject

Returns the value of attribute main_app

Returns:

  • (Object)

    the current value of main_app



11
12
13
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 11

def main_app
  @main_app
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



11
12
13
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 11

def options
  @options
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



11
12
13
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 11

def value
  @value
end

Instance Method Details

#formatted_value(value) ⇒ Object



14
15
16
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 14

def formatted_value(value)
  options[:formatter].call(value)
end

#media_type(resource) ⇒ Object



28
29
30
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 28

def media_type(resource)
  resource.media_type.to_s
end

#src(image, variant: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/flexi_admin/components/resources/grid_view_component.rb', line 18

def src(image, variant: nil)
  raise "ActiveStorage::Attached::One required, got #{image.class}" if image.class != ActiveStorage::Attached::One

  return unless variant && image.attached?

  main_app.url_for(image.variant(variant))
rescue ActiveStorage::InvariableError
  main_app.url_for(image)
end