Class: RailsAdmin::Config::Fields::Group
- 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
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Base
#abstract_model, #bindings, #parent, #root
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 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
#name ⇒ Object (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
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 |
#fields ⇒ Object
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
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_fields ⇒ Object
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 |