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?, included, #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.



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

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.



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

def abstract_model
  @abstract_model
end

#nameObject (readonly)

Returns the value of attribute name.



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

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.



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

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


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

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



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

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


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

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



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

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