Sha256: 6e5082040e26599be1fdf367df0214daff75a6f94ceb5238829ab51d134c08fd

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

require 'active_model'

module SipValidator
  class Validator
    def initialize(opts = {})
      # ruby does not allow method with -
      # replaces - with _
      opts.keys.each do |key|
        raise("#{key} incude _ which is not allowed") if key.to_s.match(/_/)
        if key.to_s.match(/-/)
          new_key = opts.keys.last.to_s.gsub('-','_')
          opts[new_key] = opts.delete key
        end
      end
      super(opts)
    end

    include ActiveModel::Model
    attr_accessor :sip, :sccp, :title, :author, :status, :created, :updated
    attr_accessor :replaces, :requires, :layer, :resolution
    # replace - with _
    attr_accessor :discussions_to, :superseded_by, :review_period_end
    validates_presence_of :title, :author, :status, :created
    validates :sip,
              presence: true,
              unless: ->(v){v.sccp.present?}
    validates :sccp, 
              presence: true, 
              unless: ->(v){v.sip.present?}
    validates_inclusion_of :status, in: ['WIP', 'Proposed', 'Approved', 'Implemented']
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sip_validator-0.1.0 lib/sip_validator/validator.rb