Module: Formeze::ClassMethods

Includes:
ArrayAttrAccessor
Defined in:
lib/formeze.rb

Instance Method Summary collapse

Methods included from ArrayAttrAccessor

#array_attr_accessor, #array_attr_reader, #array_attr_writer

Instance Method Details

#field(*args) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
# File 'lib/formeze.rb', line 196

def field(*args)
  field = Field.new(*args)

  fields << field

  if field.multiple?
    array_attr_accessor field.name
  else
    attr_accessor field.name
  end
end

#fieldsObject



192
193
194
# File 'lib/formeze.rb', line 192

def fields
  @fields ||= FieldSet.new
end

#parse(encoded_form_data) ⇒ Object



216
217
218
219
220
# File 'lib/formeze.rb', line 216

def parse(encoded_form_data)
  Kernel.warn '[formeze] the parse class method is deprecated and will be removed, please use the instance method instead'

  new.tap { |form| form.parse(encoded_form_data) }
end

#validates(field_name, options = {}, &block) ⇒ Object



212
213
214
# File 'lib/formeze.rb', line 212

def validates(field_name, options = {}, &block)
  validations << Validation.new(fields[field_name], options, &block)
end

#validationsObject



208
209
210
# File 'lib/formeze.rb', line 208

def validations
  @validations ||= []
end