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.
Attributes included from Proxyable
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.
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_model ⇒ Object (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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/rails_admin/config/fields/group.rb', line 15 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.
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
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 |
#fields ⇒ Object
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| self == f.group } end |
#fields_of_type(type, &block) ⇒ Object
Defines configuration for fields by their type
48 49 50 51 52 53 54 |
# File 'lib/rails_admin/config/fields/group.rb', line 48 def fields_of_type(type, &block) selected = section.fields.select {|f| type == f.type } if block selected.each {|f| f.instance_eval &block } end selected end |
#visible_fields ⇒ Object
Reader for fields that are marked as visible
57 58 59 |
# File 'lib/rails_admin/config/fields/group.rb', line 57 def visible_fields section.with(bindings).visible_fields.select {|f| self == f.group } end |