Class: Remarkable::Mongoid::Matchers::RelationMatcher
- Inherits:
-
Object
- Object
- Remarkable::Mongoid::Matchers::RelationMatcher
- Defined in:
- lib/remarkable/mongoid/relations.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
-
#relation_type ⇒ Object
Returns the value of attribute relation_type.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
-
#initialize(attr, relation_type) ⇒ RelationMatcher
constructor
A new instance of RelationMatcher.
- #matches?(subject) ⇒ Boolean
Constructor Details
#initialize(attr, relation_type) ⇒ RelationMatcher
Returns a new instance of RelationMatcher.
91 92 93 94 |
# File 'lib/remarkable/mongoid/relations.rb', line 91 def initialize(attr, relation_type) self.attr = attr.to_s self.relation_type = relation_type end |
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
89 90 91 |
# File 'lib/remarkable/mongoid/relations.rb', line 89 def attr @attr end |
#relation_type ⇒ Object
Returns the value of attribute relation_type.
89 90 91 |
# File 'lib/remarkable/mongoid/relations.rb', line 89 def relation_type @relation_type end |
Instance Method Details
#description ⇒ Object
102 103 104 |
# File 'lib/remarkable/mongoid/relations.rb', line 102 def description "has #{humanized_relation} relation :#{attr}" end |
#failure_message_for_should ⇒ Object
106 107 108 |
# File 'lib/remarkable/mongoid/relations.rb', line 106 def "\n#{humanized_relation} relation failure\nExpected: '#{attr}'" end |
#matches?(subject) ⇒ Boolean
96 97 98 99 100 |
# File 'lib/remarkable/mongoid/relations.rb', line 96 def matches?(subject) @subject = subject relations = @subject.relations.select { |k,v| v.relation == relation_type } relations.detect { |k| k.first == attr } != nil end |