Sha256: 5f476a09b6b3e42415cead801855041651dda605b00ebca764bead04d4f9a077
Contents?: true
Size: 1.98 KB
Versions: 1
Compression:
Stored size: 1.98 KB
Contents
require 'active_model' module IpsValidator class ValidatorFactory 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 end # 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.2 | lib/ips_validator/validator.rb |