Sha256: 0fcb25b7fe3e139e4aa03b62e827e411ffb8c6db28117756a9baaa0879f36d80

Contents?: true

Size: 575 Bytes

Versions: 11

Compression:

Stored size: 575 Bytes

Contents

class Form
  
  def initialize(key_default_pairs={})
    @fields = []
    key_default_pairs.each {|key,value| @fields << Field.new(key, value)}
  end  
  
  def update(new_values) 
    new_values.each { | key,value | find(key).update(value)}
  end
  
  def [](field)
    find(field).value
  end
  
  def is_valid?
    @fields.all? { |field| field.is_valid? }
  end
  
  def invalid(key, error)
    find(key).invalid(error)
  end
  
  def errors_for(key)
    find(key).errors
  end
  
  private
    
    def find(key)
      @fields.find { | field | field.is?(key)}
    end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
starapor-slippers-0.0.2 examples/forms/model/form.rb
starapor-slippers-0.0.3 examples/forms/model/form.rb
starapor-slippers-0.0.5 examples/forms/model/form.rb
starapor-slippers-0.0.6 examples/forms/model/form.rb
starapor-slippers-0.0.8 examples/forms/model/form.rb
starapor-slippers-0.0.9 examples/forms/model/form.rb
slippers-0.0.14 examples/forms/model/form.rb
slippers-0.0.13 examples/forms/model/form.rb
slippers-0.0.12 examples/forms/model/form.rb
slippers-0.0.11 examples/forms/model/form.rb
slippers-0.0.10 examples/forms/model/form.rb