module Simpleadmin::Decorators::FieldDecorator

Constants

FIELDS_MAPPER

Public Class Methods

call(resources, table_name, table_fields) click to toggle source
# File lib/simpleadmin/decorators/fields_decorator.rb, line 13
def call(resources, table_name, table_fields)
  resources.map do |resource|
    resource_attributes = {}

    table_fields.each do |table_field|
      table_field_name, table_field_type = *table_field.values

      if table_field_match?(table_field_type)
        field_class = FIELDS_MAPPER[table_field_type]

        resource_attributes[table_field_name] = field_class.new(table_name, table_field_name, resource).call
      else
        resource_attributes[table_field_name] = resource[table_field_name.to_sym]
      end
    end

    resource_attributes
  end
end
table_field_match?(table_field_type) click to toggle source
# File lib/simpleadmin/decorators/fields_decorator.rb, line 37
def table_field_match?(table_field_type)
  FIELDS_MAPPER.key?(table_field_type)
end

Private Instance Methods

call(resources, table_name, table_fields) click to toggle source
# File lib/simpleadmin/decorators/fields_decorator.rb, line 13
def call(resources, table_name, table_fields)
  resources.map do |resource|
    resource_attributes = {}

    table_fields.each do |table_field|
      table_field_name, table_field_type = *table_field.values

      if table_field_match?(table_field_type)
        field_class = FIELDS_MAPPER[table_field_type]

        resource_attributes[table_field_name] = field_class.new(table_name, table_field_name, resource).call
      else
        resource_attributes[table_field_name] = resource[table_field_name.to_sym]
      end
    end

    resource_attributes
  end
end
table_field_match?(table_field_type) click to toggle source
# File lib/simpleadmin/decorators/fields_decorator.rb, line 37
def table_field_match?(table_field_type)
  FIELDS_MAPPER.key?(table_field_type)
end