Module: Sunrise::Config::HasFields

Included in:
Edit, Group, List, 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, options = {}) ⇒ Object

Defines a configuration for a field.



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

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

#fieldsObject

Array for store all defined fields



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

def fields
  @fields ||= []
end

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

Defines a configuration for a nested attributes



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

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