Module: Tramway::Core::Attributes::ViewHelper

Included in:
Tramway::Core::ApplicationDecorator
Defined in:
app/decorators/tramway/core/attributes/view_helper.rb

Instance Method Summary collapse

Instance Method Details

#build_viewable_value(object, attribute) ⇒ Object



4
5
6
7
8
9
# File 'app/decorators/tramway/core/attributes/view_helper.rb', line 4

def build_viewable_value(object, attribute)
  value = try(attribute[0]) ? send(attribute[0]) : object.send(attribute[0])
  return state_machine_view(object, attribute[0]) if state_machine? object, attribute[0]

  view_by_value object, value, attribute
end

#state_machine?(object, attribute_name) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/decorators/tramway/core/attributes/view_helper.rb', line 11

def state_machine?(object, attribute_name)
  attribute_name.to_s.in? object.class.state_machines.keys.map(&:to_s)
end

#view_by_value(object, value, attribute) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'app/decorators/tramway/core/attributes/view_helper.rb', line 15

def view_by_value(object, value, attribute)
  if value.class.in? [ActiveSupport::TimeWithZone, DateTime, Time]
    datetime_view(attribute[1])
  elsif value.class.superclass == ApplicationUploader
    image_view(object.send(attribute[0]))
  elsif value.is_a? Enumerize::Value
    enumerize_view(value)
  else
    value
  end
end