Class: Remarkable::Mongoid::Matchers::RelationMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/remarkable/mongoid/relations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attrObject

Returns the value of attribute attr.



89
90
91
# File 'lib/remarkable/mongoid/relations.rb', line 89

def attr
  @attr
end

#relation_typeObject

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

#descriptionObject



102
103
104
# File 'lib/remarkable/mongoid/relations.rb', line 102

def description
  "has #{humanized_relation} relation :#{attr}"
end

#failure_message_for_shouldObject



106
107
108
# File 'lib/remarkable/mongoid/relations.rb', line 106

def failure_message_for_should
  "\n#{humanized_relation} relation failure\nExpected: '#{attr}'"
end

#matches?(subject) ⇒ Boolean

Returns:

  • (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