Sha256: 958ed05c5e1d41eb8c7eb792d1c252a5367a5f2460d4171abe53ae616c0a8a39
Contents?: true
Size: 926 Bytes
Versions: 1
Compression:
Stored size: 926 Bytes
Contents
module ACH # This module hosts the most basic validations for both +components+ and # +records+. The only validation being performed is presence validation. module Validations def valid? reset_errors! is_a?(Component) ? valid_component? : valid_record? errors.empty? end def valid_component? counts = Hash.new(0) to_ach.each do |record| unless record.valid? klass = record.class errors["#{klass}##{counts[klass] += 1}"] = record.errors end end end private :valid_component? def valid_record? self.class.fields.each do |field| errors[field] = "is required" unless fields[field] end end private :valid_record? def errors @errors || reset_errors! end def reset_errors! @errors = ActiveSupport::OrderedHash.new end private :reset_errors! end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ach_builder-0.2.1 | lib/ach/validations.rb |