Sha256: a3576621136124d430321634db6ac9cbb47aa45f82bd4b9dbc742f0cb450984c

Contents?: true

Size: 893 Bytes

Versions: 12

Compression:

Stored size: 893 Bytes

Contents

module Mongomatic
  module Validatable
    module Understandable #:nodoc:
      module ClassMethods #:nodoc:
        def understands(*args)
          understandings.concat args
        end

        def understandings
          @understandings ||= []
        end

        def all_understandings
          return understandings + self.superclass.all_understandings if self.superclass.respond_to? :all_understandings
          understandings
        end
      end

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

      def must_understand(hash)
        invalid_options = hash.inject([]) do |errors, (key, value)|
          errors << key.to_s unless self.class.all_understandings.include?(key)
          errors
        end
        raise ArgumentError.new("invalid options: #{invalid_options.join(', ')}") if invalid_options.any?
        true
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mongomatic-0.1.31 lib/mongomatic/validatable/understandable.rb
mongomatic-0.1.3 lib/mongomatic/validatable/understandable.rb
mongomatic-0.1.2 lib/mongomatic/validatable/understandable.rb
mongomatic-0.1.1 lib/mongomatic/validatable/understandable.rb
mongomatic-0.1.0 lib/mongomatic/validatable/understandable.rb
mongomatic-0.0.9 lib/mongomatic/validatable/understandable.rb
mongomatic-0.0.8 lib/mongomatic/validatable/understandable.rb
mongomatic-0.0.7 lib/mongomatic/validatable/understandable.rb
mongomatic-0.0.6 lib/mongomatic/validatable/understandable.rb
mongomatic-0.0.5 lib/mongomatic/validatable/understandable.rb
mongomatic-0.0.4 lib/mongomatic/validatable/understandable.rb
mongomatic-0.0.3 lib/mongomatic/validatable/understandable.rb