Class: Remarkable::Mongoid::Matchers::ValidateUniquenessOfMatcher
- Inherits:
-
Object
- Object
- Remarkable::Mongoid::Matchers::ValidateUniquenessOfMatcher
- Defined in:
- lib/remarkable/mongoid/validate_uniqueness_of.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#message ⇒ Object
Returns the value of attribute message.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#validation_type ⇒ Object
Returns the value of attribute validation_type.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
-
#initialize(attr) ⇒ ValidateUniquenessOfMatcher
constructor
A new instance of ValidateUniquenessOfMatcher.
- #matches?(subject) ⇒ Boolean
- #scoped_to(scope) ⇒ Object
- #with_message(message) ⇒ Object
Constructor Details
#initialize(attr) ⇒ ValidateUniquenessOfMatcher
Returns a new instance of ValidateUniquenessOfMatcher.
19 20 21 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 19 def initialize(attr) self.attr = attr.to_sym end |
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
17 18 19 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 17 def attr @attr end |
#message ⇒ Object
Returns the value of attribute message.
17 18 19 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 17 def @message end |
#scope ⇒ Object
Returns the value of attribute scope.
17 18 19 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 17 def scope @scope end |
#validation_type ⇒ Object
Returns the value of attribute validation_type.
17 18 19 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 17 def validation_type @validation_type end |
Instance Method Details
#description ⇒ Object
44 45 46 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 44 def description "validates that :#{attr} is unique" end |
#failure_message_for_should ⇒ Object
48 49 50 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 48 def "\nUniqueness validation failure\nExpected: '#{attr}' to be unique" end |
#matches?(subject) ⇒ Boolean
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 33 def matches?(subject) @subject = subject validations = @subject._validators[attr] if validations validation = validations.detect { |k| k.class == ::Mongoid::Validations::UniquenessValidator } validation && check_option(validation, :message) && check_option(validation, :scope) else false end end |
#scoped_to(scope) ⇒ Object
28 29 30 31 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 28 def scoped_to(scope) self.scope = scope.is_a?(Array) ? scope.map(&:to_sym) : scope.to_sym self end |
#with_message(message) ⇒ Object
23 24 25 26 |
# File 'lib/remarkable/mongoid/validate_uniqueness_of.rb', line 23 def () self. = self end |