Module: Sunrise::Config::HasFields

Included in:
Export, Form, Group, Index, Show
Defined in:
lib/sunrise/config/has_fields.rb

Overview

Provides accessors and autoregistering of model’s fields.

Instance Method Summary collapse

Instance Method Details

#field(name = :custom, options = {}, &block) ⇒ Object

Defines a configuration for a field.



16
17
18
19
# File 'lib/sunrise/config/has_fields.rb', line 16

def field(name = :custom, options = {}, &block)
  options = { name: name.to_sym }.merge(options)
  fields << Field.new(abstract_model, self, options, &block)
end

#fieldsObject

Array for store all defined fields



11
12
13
# File 'lib/sunrise/config/has_fields.rb', line 11

def fields
  @fields ||= []
end

#nested_attributes(name, options = {}, &block) ⇒ Object

Defines a configuration for a nested attributes



22
23
24
25
26
27
# File 'lib/sunrise/config/has_fields.rb', line 22

def nested_attributes(name, options = {}, &block)
  options = { name: name.to_sym }.merge(options)
  nested_field = NestedField.new(abstract_model, self, options)
  nested_field.instance_eval &block if block
  fields << nested_field
end