Sha256: 873760495dcd2d0c9213440fcdaa9f055550cdccca25de3f31ae3572eee9ad3f

Contents?: true

Size: 1.07 KB

Versions: 17

Compression:

Stored size: 1.07 KB

Contents

module Medivo
  class PrimaryInsurance
    include ActiveModel::Validations
    include ActiveModel::Serializers::Xml

    validates_presence_of :relationship, :company_name, :policy_number
    validates :relationship, :inclusion => {:in => 1..2}

    def initialize(attributes = {})
      @attributes = attributes
    end

    def read_attribute_for_validation(key)
      @attributes[key]
    end

    def attributes
      @attributes.stringify_keys
    end

    # for use by InsuranceOrder to validate its primary insurance
    def validate(record)
      primary_insurance = record.attributes['primary_insurance']
      record.errors.add(:primary_insurance, "primary_insurance field must be present") and return unless primary_insurance
      record.errors.add(:primary_insurance, "primary_insurance field must be of PrimaryInsurance class") and return unless primary_insurance.is_a? PrimaryInsurance
      primary_insurance.valid?
      primary_insurance.errors.messages.each do |field, value|
        record.errors.add(:"primary_insurance.#{field}", value.first)
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
medivo-0.2.21 app/models/medivo/primary_insurance.rb
medivo-0.2.20 app/models/medivo/primary_insurance.rb
medivo-0.2.19 app/models/medivo/primary_insurance.rb
medivo-0.2.18 app/models/medivo/primary_insurance.rb
medivo-0.2.17 app/models/medivo/primary_insurance.rb
medivo-0.2.16 app/models/medivo/primary_insurance.rb
medivo-0.2.15 app/models/medivo/primary_insurance.rb
medivo-0.2.14 app/models/medivo/primary_insurance.rb
medivo-0.2.13 app/models/medivo/primary_insurance.rb
medivo-0.2.12 app/models/medivo/primary_insurance.rb
medivo-0.2.11 app/models/medivo/primary_insurance.rb
medivo-0.2.10 app/models/medivo/primary_insurance.rb
medivo-0.2.9 app/models/medivo/primary_insurance.rb
medivo-0.2.8 app/models/medivo/primary_insurance.rb
medivo-0.2.7 app/models/medivo/primary_insurance.rb
medivo-0.2.6 app/models/medivo/primary_insurance.rb
medivo-0.2.5 app/models/medivo/primary_insurance.rb