Sha256: d53c1e382c2fd70a783eac702d51e778a2a8b78221d9560d05e1ebe13423580f

Contents?: true

Size: 830 Bytes

Versions: 3

Compression:

Stored size: 830 Bytes

Contents

require 'data_mapper/validations/number_validator'
require 'data_mapper/validations/string_validator'

module DataMapper
  module Types
    TYPE_MAP = {}

    module Base
      module ClassMethods
        def context(ctx)
          contexts(ctx)
        end

        def contexts(*ctxs)
          @contexts || @contexts = %w{__all__} << ctxs.map { |c| c.to_s }
        end
      end

      def self.included(klass)
        klass.extend(ClassMethods)
      end

      def do_validations
        raise NotImplementedError.new
      end

      def valid?(context = "__all__")
        @errors = []

        if self.class.contexts.include?(context.to_s) 
          do_validations

          @errors.empty?
        else 
          true
        end
      end

      def errors
        @errors || @errors = []
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
datamapper-0.3.0 lib/data_mapper/types/base.rb
datamapper-0.3.1 lib/data_mapper/types/base.rb
datamapper-0.3.2 lib/data_mapper/types/base.rb