Sha256: ed84788909a419681c5d8121023452e4177db6e770ea9dc1fc76de2c528217b1

Contents?: true

Size: 741 Bytes

Versions: 2

Compression:

Stored size: 741 Bytes

Contents

class EntityService
  def index_action
    models = []

    ApplicationRecord.descendants.each do |model|
      name = model.name
      columns = model.columns.map do |column|
        {
          name: column.name,
          type: column.sql_type.parameterize.underscore
        }
      end

      models.push(
        name: name,
        columns: columns
      )
    end

    {
      models: models
    }
  end

  def show_action(resource_klass)
    {
      name:         resource_klass.name,
      column_names: resource_klass.column_names,
      columns:      resource_klass.columns.map { |column| { name: column.name, type: column.sql_type.parameterize.underscore } },
      reflections:  resource_klass.reflections.keys
    }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simpleadmin-1.4.0 app/services/entity_service.rb
simpleadmin-1.3.0 app/services/entity_service.rb