Sha256: fd3a3098ef8f5037cf652d2a6e2160e97b67873fab9ebcbb8145947600b15e14
Contents?: true
Size: 691 Bytes
Versions: 12
Compression:
Stored size: 691 Bytes
Contents
module Datev class Field attr_accessor :name, :options, :block def initialize(name, options={}, &block) unless name.is_a?(String) raise ArgumentError.new("Argument 'name' has to be a String") end unless options.is_a?(Hash) raise ArgumentError.new("Argument 'options' has to be a Hash") end self.name = name self.options = options if block_given? self.instance_eval(&block) end end def required? options[:required] == true end def validate!(value) if value.nil? raise ArgumentError.new("Value for field '#{name}' is required") if required? end end end end
Version data entries
12 entries across 12 versions & 1 rubygems