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

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

Overview

A container for groups of fields in edit views

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hideable

#hidden?, #hide, included, #show

Methods included from Configurable

#has_option?, #register_deprecated_instance_option, #register_instance_option

Methods included from Proxyable

#bindings, #bindings=, #with

Constructor Details

#initialize(parent, name) ⇒ Group

Returns a new instance of Group.



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

def initialize(parent, name)
  @parent = parent
  @root = parent.root

  @abstract_model = parent.abstract_model
  @section = parent
  @name = name.to_s.tr(' ', '_').downcase.to_sym
end

Instance Attribute Details

#abstract_modelObject (readonly)

Returns the value of attribute abstract_model.



17
18
19
# File 'lib/rails_admin/config/fields/group.rb', line 17

def abstract_model
  @abstract_model
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/rails_admin/config/fields/group.rb', line 17

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



17
18
19
# File 'lib/rails_admin/config/fields/group.rb', line 17

def parent
  @parent
end

#rootObject (readonly)

Returns the value of attribute root.



17
18
19
# File 'lib/rails_admin/config/fields/group.rb', line 17

def root
  @root
end

#sectionObject

Returns the value of attribute section.



18
19
20
# File 'lib/rails_admin/config/fields/group.rb', line 18

def section
  @section
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


33
34
35
36
37
38
39
# File 'lib/rails_admin/config/fields/group.rb', line 33

def field(name, type = nil, &block)
  field = section.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



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

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

#fields_of_type(type, &block) ⇒ Object

Defines configuration for fields by their type

See Also:

  • RailsAdmin::Config::Fields.fields_of_type


49
50
51
52
53
# File 'lib/rails_admin/config/fields/group.rb', line 49

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

#visible_fieldsObject

Reader for fields that are marked as visible



56
57
58
# File 'lib/rails_admin/config/fields/group.rb', line 56

def visible_fields
  section.with(bindings).visible_fields.select { |f| f.group == self }
end