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
- #value(name) ⇒ Object
Constructor Details
Instance Method Details
#<<(record) ⇒ Object
447 448 449 450 451 452 453 |
# File 'lib/formkeeper.rb', line 447 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
454 455 456 |
# File 'lib/formkeeper.rb', line 454 def [](name) @valid_params[name.to_sym] end |
#failed? ⇒ Boolean
468 469 470 |
# File 'lib/formkeeper.rb', line 468 def failed? !@failed_records.empty? end |
#failed_constraints(name) ⇒ Object
480 481 482 483 484 |
# File 'lib/formkeeper.rb', line 480 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
477 478 479 |
# File 'lib/formkeeper.rb', line 477 def failed_fields @failed_records.keys end |
#failed_on?(name, constraint = nil) ⇒ Boolean
471 472 473 474 475 476 |
# File 'lib/formkeeper.rb', line 471 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
503 504 505 506 507 508 509 |
# File 'lib/formkeeper.rb', line 503 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
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/formkeeper.rb', line 485 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
465 466 467 |
# File 'lib/formkeeper.rb', line 465 def valid?(name) @valid_params.has_key?(name.to_sym) end |
#valid_fields ⇒ Object
462 463 464 |
# File 'lib/formkeeper.rb', line 462 def valid_fields @valid_params.keys end |
#value(name) ⇒ Object
457 458 459 460 461 |
# File 'lib/formkeeper.rb', line 457 def value(name) name = name.to_sym return self[name] if valid?(name) failed_fields.include?(name) ? @failed_records[name].value : nil end |