Class: SimpleAttribute::Attributes::Image
- Defined in:
- lib/simple_attribute/attributes/image.rb
Instance Attribute Summary
Attributes inherited from Base
#attribute, #options, #record, #value
Instance Method Summary collapse
- #attribute_name ⇒ Object
- #media_type ⇒ Object
- #render_attribute ⇒ Object
- #render_default_value ⇒ Object
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_name ⇒ Object
4 5 6 |
# File 'lib/simple_attribute/attributes/image.rb', line 4 def attribute_name 'image' end |
#media_type ⇒ Object
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_attribute ⇒ Object
22 23 24 |
# File 'lib/simple_attribute/attributes/image.rb', line 22 def render_attribute content_tag :img, nil, .reverse_merge(src: value) end |
#render_default_value ⇒ Object
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) content_tag :img, nil, .reverse_merge(src: default_url) end |