Class: RailsAdmin::Config::Fields::Group

Inherits:
Base
  • Object
show all
Includes:
Hideable
Defined in:
lib/rails_admin/config/fields/group.rb

Overview

A container for groups of fields in edit views

Instance Attribute Summary collapse

Attributes inherited from Base

#abstract_model, #bindings, #parent, #root

Instance Method Summary collapse

Methods included from Hideable

#hidden?, #hide, included, #show

Methods inherited from Base

#has_option?, register_class_option, #register_deprecated_instance_option, register_deprecated_instance_option, register_instance_option, #register_instance_option, #with

Constructor Details

#initialize(parent, name) ⇒ Group

Returns a new instance of Group.



13
14
15
16
# File 'lib/rails_admin/config/fields/group.rb', line 13

def initialize(parent, name)
  super(parent)
  @name = name.to_s.tr(' ', '_').downcase.to_sym
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/rails_admin/config/fields/group.rb', line 11

def name
  @name
end

Instance Method Details

#field(name, type = nil, &block) ⇒ Object

Defines a configuration for a field by proxying parent’s field method and setting the field’s group as self

See Also:

  • RailsAdmin::Config::Fields.field


22
23
24
25
26
27
28
# File 'lib/rails_admin/config/fields/group.rb', line 22

def field(name, type = nil, &block)
  field = parent.field(name, type, &block)
  # Directly manipulate the variable instead of using the accessor
  # as group probably is not yet registered to the parent object.
  field.instance_variable_set("@group", self)
  field
end

#fieldsObject

Reader for fields attached to this group



31
32
33
# File 'lib/rails_admin/config/fields/group.rb', line 31

def fields
  parent.fields.select {|f| self == f.group }
end

#fields_of_type(type, &block) ⇒ Object

Defines configuration for fields by their type

See Also:

  • RailsAdmin::Config::Fields.fields_of_type


38
39
40
41
42
43
44
# File 'lib/rails_admin/config/fields/group.rb', line 38

def fields_of_type(type, &block)
  selected = fields.select {|f| type == f.type }
  if block
    selected.each {|f| f.instance_eval &block }
  end
  selected
end

#visible_fieldsObject

Reader for fields that are marked as visible



47
48
49
# File 'lib/rails_admin/config/fields/group.rb', line 47

def visible_fields
  fields.select {|f| f.with(bindings).visible? }.map{|f| f.with(bindings)}
end