class Formotion::Section
Constants
- PROPERTIES
- SERIALIZE_PROPERTIES
Attributes
form[RW]
This section's form
index[RW]
This section's index in it's form.
Public Class Methods
new(params = {})
click to toggle source
Calls superclass method
Formotion::Base::new
# File lib/formotion/section/section.rb, line 32 def initialize(params = {}) super self.form = params[:form] Formotion::Conditions.assert_nil_or_boolean(self.select_one) rows = params[:rows] || params["rows"] rows && rows.each {|row_hash| row = create_row(row_hash) } end
Public Instance Methods
build_row(&block)
click to toggle source
# File lib/formotion/section/section.rb, line 53 def build_row(&block) row = generate_row block.call(row) row.after_create self.rows << row row end
create_row(hash = {})
click to toggle source
# File lib/formotion/section/section.rb, line 61 def create_row(hash = {}) row = generate_row(hash) row.after_create self.rows << row row end
generate_row(hash = {})
click to toggle source
# File lib/formotion/section/section.rb, line 43 def generate_row(hash = {}) row = hash if hash.class == Hash row = Formotion::Row.new(hash) end row.section = WeakRef.new(self) row.index = self.rows.count row end
index=(index)
click to toggle source
# File lib/formotion/section/section.rb, line 82 def index=(index) @index = index.to_i end
next_section()
click to toggle source
# File lib/formotion/section/section.rb, line 95 def next_section # if there are more sections in this form, use that. if self.index < self.form.sections.count - 1 return self.form.sections[self.index + 1] end nil end
previous_section()
click to toggle source
# File lib/formotion/section/section.rb, line 104 def previous_section # if there are more sections in this form, use that. if self.index > 0 return self.form.sections[self.index - 1] end nil end
refresh_row_indexes()
click to toggle source
# File lib/formotion/section/section.rb, line 113 def refresh_row_indexes rows.each_with_index do |row, index| row.index = index end end
rows()
click to toggle source
attribute overrides
# File lib/formotion/section/section.rb, line 71 def rows @rows ||= [] end
rows=(rows)
click to toggle source
# File lib/formotion/section/section.rb, line 75 def rows=(rows) rows.each {|row| Formotion::Conditions.assert_class(row, Formotion::Row) } @rows = rows end
select_one?()
click to toggle source
should be done with alias_method but there's currently a bug in RM which messes up attr_accessors with alias_method
# File lib/formotion/section/section.rb, line 91 def select_one? self.select_one end
to_hash()
click to toggle source
Retreiving data
Calls superclass method
Formotion::Base#to_hash
# File lib/formotion/section/section.rb, line 121 def to_hash h = super h[:rows] = [] self.rows.each do |row| h[:rows] << row.to_hash if row.template_parent.nil? end h end