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 48 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 next if fields.detect { |f| f.name == properties.name } # Loop through factories until one returns true @@registry.detect { |factory| factory.call(parent, properties, fields) } end # Load fields for all associations (relations) parent.abstract_model.associations.reject { |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 next if fields.detect { |f| f.name == association.name } # Loop through factories until one returns true @@registry.detect { |factory| factory.call(parent, association, fields) } 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 75 def self.register_factory(&block) @@registry.unshift(block) end