module RailsAdmin::Config::Fields

Public Class Methods

factory(parent) click to toggle source

Build an array of fields by the provided parent object’s abstract_model’s property and association information. Each property and association is passed to the registered field factories which will populate the fields array that will be returned.

@see RailsAdmin::Config::Fields.registry

# File lib/rails_admin/config/fields.rb, line 46
def self.factory(parent)
  fields = []
  # Load fields for all properties (columns)

  parent.abstract_model.properties.each do |properties|
    # Unless a previous factory has already loaded current field as well
    unless fields.find {|f| f.name == properties[:name] }
      # Loop through factories until one returns true
      @@registry.find {|factory| factory.call(parent, properties, fields) }
    end
  end
  # Load fields for all associations (relations)
  parent.abstract_model.associations.select{|a| a[:type] != :belongs_to }.each do |association| # :belongs_to are created by factory for belongs_to fields
    # Unless a previous factory has already loaded current field as well
    unless fields.find {|f| f.name == association[:name] }
      # Loop through factories until one returns true
      @@registry.find {|factory| factory.call(parent, association, fields) }
    end
  end
  fields
end
register_factory(&block) click to toggle source

Register a field factory to be included in the factory stack.

Factories are invoked lifo (last in first out).

@see RailsAdmin::Config::Fields.registry

# File lib/rails_admin/config/fields.rb, line 73
def self.register_factory(&block)
  @@registry.unshift(block)
end