Class: Tramway::Core::ApplicationDecorator
- Inherits:
-
Object
- Object
- Tramway::Core::ApplicationDecorator
- Includes:
- ActionView::Context, ActionView::Helpers, FontAwesome::Rails::IconHelper
- Defined in:
- app/decorators/tramway/core/application_decorator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(object) ⇒ ApplicationDecorator
constructor
A new instance of ApplicationDecorator.
- #link ⇒ Object
- #model ⇒ Object
- #name ⇒ Object
Constructor Details
#initialize(object) ⇒ ApplicationDecorator
Returns a new instance of ApplicationDecorator.
6 7 8 |
# File 'app/decorators/tramway/core/application_decorator.rb', line 6 def initialize(object) @object = object end |
Class Method Details
.decorate(object_or_array) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/decorators/tramway/core/application_decorator.rb', line 19 def decorate(object_or_array) if object_or_array.class.superclass == ActiveRecord::Relation decorated_array = object_or_array.map do |obj| new obj end Tramway::Core::ApplicationDecoratedCollection.new decorated_array, object_or_array else new object_or_array end end |
.list_attributes ⇒ Object
15 16 17 |
# File 'app/decorators/tramway/core/application_decorator.rb', line 15 def list_attributes [] end |
Instance Method Details
#attributes ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/decorators/tramway/core/application_decorator.rb', line 43 def attributes object.attributes.reduce({}) do |hash, attribute| value = try(attribute[0]) ? send(attribute[0]) : object.send(attribute[0]) if attribute[0].to_s.in? object.class.state_machines.keys.map(&:to_s) hash.merge! attribute[0] => object.send("human_#{attribute[0]}_name") elsif value.class.in? [ ActiveSupport::TimeWithZone, DateTime, Time ] hash.merge! attribute[0] => I18n.l(attribute[1]) elsif value.class.superclass == ApplicationUploader = content_tag(:div) do if value.url.match(/jpg|JPG|png|PNG$/) concat image_tag value.try(:small) ? value.small.url : value.url end concat link_to(fa_icon(:download), value.url, class: 'btn btn-success') end hash.merge! attribute[0] => elsif value.is_a? Enumerize::Value hash.merge! attribute[0] => value.text else hash.merge! attribute[0] => value end end end |
#link ⇒ Object
35 36 37 |
# File 'app/decorators/tramway/core/application_decorator.rb', line 35 def link object.file.url end |
#model ⇒ Object
39 40 41 |
# File 'app/decorators/tramway/core/application_decorator.rb', line 39 def model object end |
#name ⇒ Object
10 11 12 |
# File 'app/decorators/tramway/core/application_decorator.rb', line 10 def name object.try(:name) || object.try(:title) || title end |