Class: IpsValidator::ValidatorFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/ips_validator/validator.rb

Class Method Summary collapse

Class Method Details

.make(name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ips_validator/validator.rb', line 5

def self.make(name)
  Class.new do
    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 name, :title, :author, :status, :created, :updated, :implementation
    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 name, presence: true
    validates_inclusion_of :status, in: ['WIP', 'Proposed', 'Approved', 'Implemented', 'Rejected']
  end
end