Class: Mongoid::Matchers::HaveIndexMatcher
- Defined in:
- lib/matchers/document/have_index.rb
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
Returns the value of attribute attrs.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
-
#initialize(*attrs) ⇒ HaveIndexMatcher
constructor
A new instance of HaveIndexMatcher.
- #matches?(subject) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(*attrs) ⇒ HaveIndexMatcher
Returns a new instance of HaveIndexMatcher.
13 14 15 |
# File 'lib/matchers/document/have_index.rb', line 13 def initialize *attrs @attrs = attrs.map(&:to_sym) end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
Returns the value of attribute attrs.
11 12 13 |
# File 'lib/matchers/document/have_index.rb', line 11 def attrs @attrs end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
11 12 13 |
# File 'lib/matchers/document/have_index.rb', line 11 def klass @klass end |
Instance Method Details
#description ⇒ Object
30 31 32 |
# File 'lib/matchers/document/have_index.rb', line 30 def description "have an index for #{attrs.inspect}" end |
#failure_message ⇒ Object
22 23 24 |
# File 'lib/matchers/document/have_index.rb', line 22 def "#{klass} to #{description}, but only found indexes #{indexes.inspect}" end |
#matches?(subject) ⇒ Boolean
17 18 19 20 |
# File 'lib/matchers/document/have_index.rb', line 17 def matches? subject @klass = class_of subject .any? { |idx, _| idx.keys == attrs } end |
#negative_failure_message ⇒ Object
26 27 28 |
# File 'lib/matchers/document/have_index.rb', line 26 def "#{klass} to not #{description}, but found an index for #{attrs.inspect}" end |