Sha256: fb7a216418f72d75965d39499a7ffd44d4532099a68e6efd210468376f23b1ac

Contents?: true

Size: 1.2 KB

Versions: 26

Compression:

Stored size: 1.2 KB

Contents

module Neo4j
	module Rails
		module Validations
			extend ActiveSupport::Concern
			
			class UniquenessValidator < ActiveModel::EachValidator
				def initialize(options)
					super(options.reverse_merge(:case_sensitive => true))
				end
	
				def setup(klass)
					@attributes.each do |attribute|
						if klass.index_type_for(attribute) != :exact
							raise "Can't validate property #{attribute.inspect} on class #{klass} since there is no :exact lucene index on that property or the index declaration #{attribute} comes after the validation declaration in #{klass} (try to move it before the validation rules)"
						end
					end
				end
	
				def validate_each(record, attribute, value)
					return if options[:allow_blank] && value.blank?
					record.class.all("#{attribute}: \"#{value}\"").each do |rec|
            if rec.id != record.id # it doesn't count if we find ourself!
              record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
              break
            end
					end
				end
			end
	
			module ClassMethods
				def validates_uniqueness_of(*attr_names)
					validates_with UniquenessValidator, _merge_attributes(attr_names)
				end
			end
		end
	end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
neo4j-1.2.4-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.2.3-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.2.2-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.2.1-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.2.0-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.1.4-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.1.3-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.1.2-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.1.1-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.1.0-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.1.0.beta.3-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.1.0.beta.2-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.1.0.beta.1-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.0.0-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.0.0.beta.32-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.0.0.beta.31-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.0.0.beta.30-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.0.0.beta.29-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.0.0.beta.28-java lib/neo4j/rails/validations/uniqueness.rb
neo4j-1.0.0.beta.27-java lib/neo4j/rails/validations/uniqueness.rb