Class: RailsAdmin::Config::Fields::Group
- Inherits:
-
Object
- Object
- RailsAdmin::Config::Fields::Group
- 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
-
#abstract_model ⇒ Object
readonly
Returns the value of attribute abstract_model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#section ⇒ Object
Returns the value of attribute section.
Instance Method Summary collapse
-
#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.
-
#fields ⇒ Object
Reader for fields attached to this group.
-
#fields_of_type(type, &block) ⇒ Object
Defines configuration for fields by their type.
-
#initialize(parent, name) ⇒ Group
constructor
A new instance of Group.
-
#visible_fields ⇒ Object
Reader for fields that are marked as visible.
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
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_model ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/rails_admin/config/fields/group.rb', line 17 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
17 18 19 |
# File 'lib/rails_admin/config/fields/group.rb', line 17 def parent @parent end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
17 18 19 |
# File 'lib/rails_admin/config/fields/group.rb', line 17 def root @root end |
#section ⇒ Object
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
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 |
#fields ⇒ Object
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
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_fields ⇒ Object
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 |