lib/neo4j/active_node/validations.rb:23
#found
+ show/hide codedef found(record, attribute, value) conditions = scope_conditions(record) # TODO: Added as find(:name => nil) throws error value = '' if value.nil? conditions[attribute] = options[:case_sensitive] ? value : /^#{Regexp.escape(value.to_s)}$/i found = record.class.as(:result).where(conditions) found = found.where('ID(result) <> {record_neo_id}').params(record_neo_id: record.neo_id) if record._persisted_obj found end
def found(record, attribute, value) conditions = scope_conditions(record) # TODO: Added as find(:name => nil) throws error value = '' if value.nil? conditions[attribute] = options[:case_sensitive] ? value : /^#{Regexp.escape(value.to_s)}$/i found = record.class.as(:result).where(conditions) found = found.where('ID(result) <> {record_neo_id}').params(record_neo_id: record.neo_id) if record._persisted_obj found end
#initialize
+ show/hide codedef initialize(options) super(options.reverse_merge(case_sensitive: true)) end
def initialize(options) super(options.reverse_merge(case_sensitive: true)) end
#message
+ show/hide codedef message(instance) super || 'has already been taken' end
def message(instance) super || 'has already been taken' end
#scope_conditions
+ show/hide codedef scope_conditions(instance) Array(options[:scope] || []).inject({}) do |conditions, key| conditions.merge(key => instance[key]) end end
def scope_conditions(instance) Array(options[:scope] || []).inject({}) do |conditions, key| conditions.merge(key => instance[key]) end end
#validate_each
+ show/hide codedef validate_each(record, attribute, value) return unless found(record, attribute, value).exists? record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(value: value)) end
def validate_each(record, attribute, value) return unless found(record, attribute, value).exists? record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(value: value)) end