Sha256: 38adee2923f6f6453c7faf10a6e448a99c06fb2c7d28e1bcae3bebab9f336670

Contents?: true

Size: 570 Bytes

Versions: 7

Compression:

Stored size: 570 Bytes

Contents

require 'ostruct'
require 'active_model'

module Jamef
  
  class Sender < OpenStruct
    
    include ActiveModel::Validations
    
    validates :document, :city, :state, :jamef_branch, presence: true
    
    validates :state, length: {is: 2}
    
    validate :validate_branch
    
    def initialize *args
      super
      raise ArgumentError, errors.first unless self.valid?
      self
    end
    
    def validate_branch
      errors.add(:jamef_branch,'Unknown branch') if jamef_branch.present? and Jamef::Branch.find(jamef_branch).blank?
    end
    
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
jamef-api-0.5.6 lib/jamef/sender.rb
jamef-api-0.5.5 lib/jamef/sender.rb
jamef-api-0.5.4 lib/jamef/sender.rb
jamef-api-0.5.3 lib/jamef/sender.rb
jamef-api-0.5.2 lib/jamef/sender.rb
jamef-api-0.5.1 lib/jamef/sender.rb
jamef-api-0.5.0 lib/jamef/sender.rb