Sha256: f5e83477e0b107a9c19b5044478c83b52d88d807b66f0e6f959882c1ba9adc2b

Contents?: true

Size: 942 Bytes

Versions: 3

Compression:

Stored size: 942 Bytes

Contents

# frozen_string_literal: true

module Tramway::Attributes::ViewHelper
  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

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

  def view_by_value(object, value, attribute)
    if value.class.in? [ActiveSupport::TimeWithZone, DateTime, Time]
      datetime_view(attribute[1])
    elsif value.instance_of?(PhotoUploader)
      image_view(object.send(attribute[0]))
    elsif value.instance_of?(FileUploader)
      file_view(object.send(attribute[0]))
    elsif value.is_a? Enumerize::Value
      enumerize_view(value)
    elsif value.is_a? Hash
      yaml_view(value)
    else
      value
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tramway-0.1.2 app/decorators/tramway/attributes/view_helper.rb
tramway-0.1.1.1 app/decorators/tramway/attributes/view_helper.rb
tramway-0.1.1 app/decorators/tramway/attributes/view_helper.rb