Class: XLFormSectionDescriptor

Inherits:
Object
  • Object
show all
Defined in:
lib/ProMotion/XLForm/xl_form_patch.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#section_dataObject

Returns the value of attribute section_data.



99
100
101
# File 'lib/ProMotion/XLForm/xl_form_patch.rb', line 99

def section_data
  @section_data
end

Class Method Details

.parse_section_options(options) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ProMotion/XLForm/xl_form_patch.rb', line 132

def self.parse_section_options(options)
  return section_options(:none) if options.nil?

  opts = section_options(:none)
  unless options.is_a?(Array)
    options = [options]
  end
  options.each do |opt|
    opts |= section_options(opt)
  end

  opts
end

.section(section_data) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ProMotion/XLForm/xl_form_patch.rb', line 101

def self.section(section_data)
  title = section_data[:title]

  options = section_data.fetch(:options, :none)
  options = parse_section_options(options)
  insert_mode = section_insert_mode(section_data[:insert_mode])

  section = XLFormSectionDescriptor.formSectionWithTitle(title, sectionOptions: options, sectionInsertMode: insert_mode)
  section.section_data = section_data

  section
end

.section_insert_mode(symbol) ⇒ Object



146
147
148
149
150
151
# File 'lib/ProMotion/XLForm/xl_form_patch.rb', line 146

def self.section_insert_mode(symbol)
  {
    last_row: XLFormSectionInsertModeLastRow,
    button: XLFormSectionInsertModeButton
  }[symbol] || symbol || XLFormSectionInsertModeLastRow
end

.section_options(symbol) ⇒ Object



153
154
155
156
157
158
159
160
# File 'lib/ProMotion/XLForm/xl_form_patch.rb', line 153

def self.section_options(symbol)
  {
    none: XLFormSectionOptionNone,
    insert: XLFormSectionOptionCanInsert,
    delete: XLFormSectionOptionCanDelete,
    reorder: XLFormSectionOptionCanReorder
  }[symbol] || symbol || XLFormSectionOptionNone
end

Instance Method Details

#options=(value) ⇒ Object



114
115
116
# File 'lib/ProMotion/XLForm/xl_form_patch.rb', line 114

def options=(value)
  @section_options = self.class.parse_section_options(value)
end

#originalSectionOptionsObject

Since ‘sectionOptions` is a property on the Objective-C class and not a Ruby method we can’t use ‘super` to fallback when overriding the method. To achieve the same thing we create an alias and use that instead.



121
# File 'lib/ProMotion/XLForm/xl_form_patch.rb', line 121

alias :originalSectionOptions :sectionOptions

#sectionOptionsObject Also known as: options

This property/method is used in the Objective-C initializer and is called before we ever have a chance to set @section_options so we need to be able to fallback to the original.



126
127
128
# File 'lib/ProMotion/XLForm/xl_form_patch.rb', line 126

def sectionOptions
  @section_options || originalSectionOptions
end