Sha256: c7cdf977c65fa3cbd4985d61f2da6c35bd0f5bcdf3b33da20de9ab10564dbc04

Contents?: true

Size: 856 Bytes

Versions: 8

Compression:

Stored size: 856 Bytes

Contents

module Gorillib
  module Model
    module Validate
      module_function

      VALID_NAME_RE = /\A[A-Za-z_][A-Za-z0-9_]*\z/
      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

      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

      def included_in!(desc, val, colxn)
        raise ArgumentError, "#{desc} must be one of #{colxn.inspect}: got #{val.inspect}", caller unless colxn.include?(val)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
gorillib-model-0.0.3 lib/gorillib/model/validate.rb
gorillib-model-0.0.1 lib/gorillib/model/validate.rb
gorillib-0.6.0 lib/gorillib/model/validate.rb
gorillib-0.5.2 lib/gorillib/model/validate.rb
gorillib-0.5.0 lib/gorillib/model/validate.rb
gorillib-0.4.2 lib/gorillib/model/validate.rb
gorillib-0.4.2pre lib/gorillib/model/validate.rb
gorillib-0.4.1pre lib/gorillib/model/validate.rb