module Gorillib::Model::Validate
Constants
- VALID_NAME_RE
Public Instance Methods
hashlike!(val)
click to toggle source
# File lib/gorillib/model/validate.rb, line 12 def hashlike!(val) return true if val.respond_to?(:[]) && val.respond_to?(:has_key?) raise ArgumentError, "#{block_given? ? yield : 'value'} should be something that behaves like a hash: #{val.inspect}", caller end
identifier!(name)
click to toggle source
# File lib/gorillib/model/validate.rb, line 7 def identifier!(name) raise TypeError, "can't convert #{name.class} into Symbol", caller unless name.respond_to? :to_sym raise ArgumentError, "Name must start with [A-Za-z_] and subsequently contain only [A-Za-z0-9_]", caller unless name =~ VALID_NAME_RE end
included_in!(desc, val, colxn)
click to toggle source
# File lib/gorillib/model/validate.rb, line 17 def included_in!(desc, val, colxn) raise ArgumentError, "#{desc} must be one of #{colxn.inspect}: got #{val.inspect}", caller unless colxn.include?(val) end