Module: SuperForm::ClassMethods
- Defined in:
- lib/super_form.rb
Instance Method Summary collapse
- #child_form_fieldsets ⇒ Object
-
#field(name, field_class, options = {}) ⇒ Object
take care of branches here.
- #fields ⇒ Object
-
#fieldset(id) ⇒ Object
fieldset may be extracted as a domain object.
- #form?(field_id = nil) ⇒ Boolean
- #setup(&block) ⇒ Object
Instance Method Details
#child_form_fieldsets ⇒ Object
142 143 144 |
# File 'lib/super_form.rb', line 142 def child_form_fieldsets @child_form_fieldsets ||= {} end |
#field(name, field_class, options = {}) ⇒ Object
take care of branches here
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/super_form.rb', line 147 def field(name, field_class, = {}) if field_class.ancestors.include? SuperForm child_form_fieldsets[name] = current_fieldset_name attribute name, field_class define_method(name) do var = :"@#{name.to_s}" value = instance_variable_get(var) unless value value = instance_variable_set(var, field_class.new) end value end create_child_validation(name) field = name else field = field_class.new(name, current_fieldset_name) field.add_validations(self, ) field.add_attributes(self, ) alias_method :"original_#{name.to_s}=", "#{name}=" define_method "#{name}=" do |value| field = self.field(name) field.value = value if field send "original_#{name.to_s}=", value end end fields[name] = field end |
#fields ⇒ Object
184 185 186 |
# File 'lib/super_form.rb', line 184 def fields @fields ||= {} end |
#fieldset(id) ⇒ Object
fieldset may be extracted as a domain object
136 137 138 139 140 |
# File 'lib/super_form.rb', line 136 def fieldset(id) initialize_fieldset(id) yield close_fieldset end |
#form?(field_id = nil) ⇒ Boolean
131 132 133 |
# File 'lib/super_form.rb', line 131 def form?(field_id = nil) field_id.nil? ? true : child_form_fieldsets.has_key?(field_id) end |
#setup(&block) ⇒ Object
126 127 128 129 |
# File 'lib/super_form.rb', line 126 def setup(&block) @setup = block if block @setup end |