Sha256: 3fbe0b2fa741932f815ad143bd999d4333fc1f092b3a5b6cc266cfb14464bda3

Contents?: true

Size: 812 Bytes

Versions: 9

Compression:

Stored size: 812 Bytes

Contents

module MongoModel
  module Validations
    extend ActiveSupport::Concern
    
    include ActiveModel::Validations
    
    module ClassMethods
      def property(name, *args, &block) #:nodoc:
        property = super
        
        if property.validate?
          validates_associated(name) if property.embeddable?
          validates_presence_of(name) if property.options[:required]
          validates_format_of(name, property.options[:format]) if property.options[:format]
        end
        
        property
      end
    end
    
    def valid?(context=nil)
      context ||= new_record? ? :create : :update
      super
    end
  end
end

Dir[File.dirname(__FILE__) + "/validations/*.rb"].sort.each do |path|
  filename = File.basename(path)
  require "mongomodel/concerns/validations/#{filename}"
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mongomodel-0.5.5 lib/mongomodel/concerns/validations.rb
mongomodel-0.5.4 lib/mongomodel/concerns/validations.rb
mongomodel-0.5.3 lib/mongomodel/concerns/validations.rb
mongomodel-0.5.2 lib/mongomodel/concerns/validations.rb
mongomodel-0.5.1 lib/mongomodel/concerns/validations.rb
mongomodel-0.5.0 lib/mongomodel/concerns/validations.rb
mongomodel-0.4.9 lib/mongomodel/concerns/validations.rb
mongomodel-0.4.8 lib/mongomodel/concerns/validations.rb
mongomodel-0.4.7 lib/mongomodel/concerns/validations.rb