Class: Mongoa::MongoMapper::Matchers::ValidateInclusionOfMatcher

Inherits:
ValidateBase
  • Object
show all
Defined in:
lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb

Instance Attribute Summary

Attributes inherited from ValidateBase

#attribute

Instance Method Summary collapse

Constructor Details

#initialize(attribute, within) ⇒ ValidateInclusionOfMatcher

Returns a new instance of ValidateInclusionOfMatcher.



5
6
7
8
# File 'lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb', line 5

def initialize(attribute, within)
  super(attribute)
  @within = within
end

Instance Method Details

#descriptionObject



15
16
17
# File 'lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb', line 15

def description
  "require #{@attribute} to be within #{@within}"
end

#failure_messageObject



19
20
21
# File 'lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb', line 19

def failure_message
  "Expected #{@attribute} to be within #{@within} but was not"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb', line 10

def matches?(subject)
  super(subject)
  @validation ? within == @within : false
end

#negative_failure_messageObject



23
24
25
# File 'lib/mongoa/mongo_mapper/validations/validate_inclusion_of.rb', line 23

def negative_failure_message
  "Expected #{@attribute} to not be within #{@within} but was"
end