Class: FormKeeper::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/formkeeper.rb

Constant Summary collapse

@@filter_store =
{}
@@constraint_store =
{}
@@combination_constraint_store =
{}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeValidator

Returns a new instance of Validator.



739
740
# File 'lib/formkeeper.rb', line 739

def initialize
end

Class Method Details

.register_combination_constraint(name, constraint) ⇒ Object



709
710
711
# File 'lib/formkeeper.rb', line 709

def self.register_combination_constraint(name, constraint)
  @@combination_constraint_store[name] = constraint
end

.register_constraint(name, constraint) ⇒ Object



705
706
707
# File 'lib/formkeeper.rb', line 705

def self.register_constraint(name, constraint)
  @@constraint_store[name] = constraint
end

.register_filter(name, filter) ⇒ Object



701
702
703
# File 'lib/formkeeper.rb', line 701

def self.register_filter(name, filter)
  @@filter_store[name] = filter
end

Instance Method Details

#validate(params, rule, messages = nil) ⇒ Object



742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
# File 'lib/formkeeper.rb', line 742

def validate(params, rule, messages=nil)
  report = Report.new(messages)
  rule.fields.each do |name, criteria|
    criteria.filters.concat(rule.default_filters)
    report << validate_field(name, criteria, params, rule.encoding_filter)
  end
  rule.checkboxes.each do |name, criteria|
    criteria.filters.concat(rule.default_filters)
    report << validate_checkbox(name, criteria, params, rule.encoding_filter)
  end
  rule.combinations.each do |name, criteria|
    criteria.filters.concat(rule.default_filters)
    report << validate_combination(name, criteria, params, rule.encoding_filter)
  end
  return report
end