Sha256: 9930046f38a79cdd2d3efbf74fdafbeaa53e2473f00c8b45b25bfb8ce86772f0

Contents?: true

Size: 930 Bytes

Versions: 1

Compression:

Stored size: 930 Bytes

Contents

require 'active_model'

module IpsValidator
  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 :fip, :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 :fip, presence: true
    validates_inclusion_of :status, in: ['WIP', 'Proposed', 'Approved', 'Implemented', 'Rejected']
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ips_validator-0.1.1 lib/ips_validator/validator.rb