Class: FormKeeper::Report
- Inherits:
-
Object
- Object
- FormKeeper::Report
- Defined in:
- lib/formkeeper.rb
Instance Method Summary collapse
- #<<(record) ⇒ Object
- #[](name) ⇒ Object
- #failed? ⇒ Boolean
- #failed_constraints(name) ⇒ Object
- #failed_fields ⇒ Object
- #failed_on?(name, constraint = nil) ⇒ Boolean
-
#initialize(messages = nil) ⇒ Report
constructor
A new instance of Report.
- #message(action, name, constraint) ⇒ Object
- #messages(action, name = nil) ⇒ Object
- #valid?(name) ⇒ Boolean
- #valid_fields ⇒ Object
Constructor Details
Instance Method Details
#<<(record) ⇒ Object
440 441 442 443 444 445 446 |
# File 'lib/formkeeper.rb', line 440 def <<(record) if record.failed? @failed_records[record.name.to_sym] = record else @valid_params[record.name.to_sym] = record.value end end |
#[](name) ⇒ Object
447 448 449 |
# File 'lib/formkeeper.rb', line 447 def [](name) @valid_params[name.to_sym] end |
#failed? ⇒ Boolean
456 457 458 |
# File 'lib/formkeeper.rb', line 456 def failed? !@failed_records.empty? end |
#failed_constraints(name) ⇒ Object
468 469 470 471 472 |
# File 'lib/formkeeper.rb', line 468 def failed_constraints(name) return [] unless @failed_records.has_key?(name.to_sym) record = @failed_records[name.to_sym] record.failed_constraints end |
#failed_fields ⇒ Object
465 466 467 |
# File 'lib/formkeeper.rb', line 465 def failed_fields @failed_records.keys end |
#failed_on?(name, constraint = nil) ⇒ Boolean
459 460 461 462 463 464 |
# File 'lib/formkeeper.rb', line 459 def failed_on?(name, constraint=nil) return false unless @failed_records.has_key?(name.to_sym) return true if constraint.nil? record = @failed_records[name.to_sym] record.failed_by?(constraint) end |
#message(action, name, constraint) ⇒ Object
491 492 493 494 495 496 497 |
# File 'lib/formkeeper.rb', line 491 def (action, name, constraint) if @failed_records.has_key?(name.to_sym) and @failed_records[name.to_sym].failed_by?(constraint) @messages.get(action, name, constraint) else nil end end |
#messages(action, name = nil) ⇒ Object
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/formkeeper.rb', line 473 def (action, name=nil) = [] if name.nil? @failed_records.values.each do |record| record.failed_constraints.each do |constraint| << @messages.get(action, record.name, constraint) end end else if @failed_records.has_key?(name.to_sym) record = @failed_records[name.to_sym] record.failed_constraints.each do |constraint| << @messages.get(action, record.name, constraint) end end end .select{ |m| !m.nil? and !m.empty? }.uniq end |
#valid?(name) ⇒ Boolean
453 454 455 |
# File 'lib/formkeeper.rb', line 453 def valid?(name) @valid_params.has_key?(name.to_sym) end |
#valid_fields ⇒ Object
450 451 452 |
# File 'lib/formkeeper.rb', line 450 def valid_fields @valid_params.keys end |