Class Validatable::ValidatesUniquenessOf
In: lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb
lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb
Parent: ValidationBase

Methods

Public Instance methods

[Source]

    # File lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb, line 9
 9:     def case_sensitive?
10:       case_sensitive
11:     end

[Source]

    # File lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb, line 9
 9:     def case_sensitive?
10:       case_sensitive
11:     end

[Source]

   # File lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb, line 5
5:     def message(instance)
6:       super || '%s has already been taken'.t(humanized_attribute)
7:     end

[Source]

   # File lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb, line 5
5:     def message(instance)
6:       super || '%s has already been taken'.t(humanized_attribute)
7:     end

[Source]

    # File lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb, line 13
13:     def valid?(instance)
14:       value = instance.send(self.attribute)
15:       return true if allow_nil && value.nil?
16:       
17:       finder_options = if case_sensitive?
18:         { self.attribute => value }
19:       else
20:         { self.attribute.like => value }
21:       end
22:       
23:       if scope 
24:         if scope.kind_of?(Array) # if scope is larger than just one property, check them all
25:           scope.each do |scope_property|
26:             scope_value = instance.send(scope_property)
27:             finder_options.merge! scope_property => scope_value
28:           end
29:         else
30:           scope_value = instance.send(scope)
31:           finder_options.merge! scope => scope_value
32:         end
33:       end
34:       
35:       finder_options.merge!({ instance.database_context.table(instance.class).key.name.not => instance.key }) unless instance.new_record?
36:       instance.database_context.first(instance.class, finder_options).nil?
37:     end

[Source]

    # File lib/data_mapper/validatable_extensions/validations/validates_uniqueness_of.rb, line 13
13:     def valid?(instance)
14:       value = instance.send(self.attribute)
15:       return true if allow_nil && value.nil?
16:       
17:       finder_options = if case_sensitive?
18:         { self.attribute => value }
19:       else
20:         { self.attribute.like => value }
21:       end
22:       
23:       if scope 
24:         if scope.kind_of?(Array) # if scope is larger than just one property, check them all
25:           scope.each do |scope_property|
26:             scope_value = instance.send(scope_property)
27:             finder_options.merge! scope_property => scope_value
28:           end
29:         else
30:           scope_value = instance.send(scope)
31:           finder_options.merge! scope => scope_value
32:         end
33:       end
34:       
35:       finder_options.merge!({ instance.database_context.table(instance.class).key.name.not => instance.key }) unless instance.new_record?
36:       instance.database_context.first(instance.class, finder_options).nil?
37:     end

[Validate]