Sha256: 86e737027f89b3330527f0de367dfd2ca324f8446978587d424ffe953fc61ade

Contents?: true

Size: 938 Bytes

Versions: 35

Compression:

Stored size: 938 Bytes

Contents

# frozen_string_literal: true

module Tramway::Core::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.class == PhotoUploader
      image_view(object.send(attribute[0]))
    elsif value.class == 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

35 entries across 35 versions & 1 rubygems

Version Path
tramway-core-5.0 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.1.3.3 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.1.3.2 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.1.3.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.1.3 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.1.2 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.1.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.0.2.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.0.2 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.0.1.2 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.0.1.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.0.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.0.0.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-4.0 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-3.0.1.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-3.0.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-3.0.0.2 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-3.0.0.1 app/decorators/tramway/core/attributes/view_helper.rb
tramway-core-3.0 app/decorators/tramway/core/attributes/view_helper.rb