Sha256: b48ee1e6de162fa7bb97c6f849b7056734bc4982c027eb9bbcbfc647015b6c13

Contents?: true

Size: 439 Bytes

Versions: 35

Compression:

Stored size: 439 Bytes

Contents

module MongoDoc
  module Validations
    module ValidatesEmbedded
      def validates_embedded(*attr_names)
        validates_with EmbeddedValidator, _merge_attributes(attr_names)
      end

      class EmbeddedValidator < ::ActiveModel::EachValidator
        def validate(record)
          attributes.each do |attr|
            record.errors.add(attr) unless record.send(attr).valid?
          end
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
mongo_doc-0.6.13 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.12 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.11 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.10 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.9 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.8 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.7 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.6 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.5 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.4 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc_rails2-0.6.2 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.3 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.2 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.1 lib/mongo_doc/validations/validates_embedded.rb
mongo_doc-0.6.0 lib/mongo_doc/validations/validates_embedded.rb