Class: SimpleAttribute::Attributes::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/simple_attribute/attributes/image.rb

Instance Attribute Summary

Attributes inherited from Base

#attribute, #options, #record, #value

Instance Method Summary collapse

Methods inherited from Base

#default_value, #defaults, #html_options, #initialize, #label_method, #method_missing, #render, #render_with_default, #render_wrapper, #renderer_name, #value?, #wrapper, #wrapper?, #wrapper_html

Constructor Details

This class inherits a constructor from SimpleAttribute::Attributes::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SimpleAttribute::Attributes::Base

Instance Method Details

#attribute_nameObject



4
5
6
# File 'lib/simple_attribute/attributes/image.rb', line 4

def attribute_name
  'image'
end

#media_typeObject



8
9
10
11
12
13
# File 'lib/simple_attribute/attributes/image.rb', line 8

def media_type
  @media_type ||= begin
    type = MiniMime.lookup_by_filename(default_value.to_s)
    type.content_type.to_s.split('/').first
  end
end

#render_attributeObject



22
23
24
# File 'lib/simple_attribute/attributes/image.rb', line 22

def render_attribute
   :img, nil, html_options.reverse_merge(src: value)
end

#render_default_valueObject



15
16
17
18
19
20
# File 'lib/simple_attribute/attributes/image.rb', line 15

def render_default_value
  return super unless 'image'.in?(media_type.to_s)

  default_url = asset_url(default_value)
   :img, nil, html_options.reverse_merge(src: default_url)
end