Class: Cuprum::Collections::Constraints::Order::ComplexOrdering

Inherits:
Stannum::Constraints::Base
  • Object
show all
Defined in:
lib/cuprum/collections/constraints/order/complex_ordering.rb

Overview

Asserts that the object is an attributes Array with an sort order Hash.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceCuprum::Collections::Constraints::Order::AttributesArray

Returns a cached instance of the constraint with default options.

Returns:



12
13
14
# File 'lib/cuprum/collections/constraints/order/complex_ordering.rb', line 12

def self.instance
  @instance ||= new
end

Instance Method Details

#matches?(actual) ⇒ true, false Also known as: match?

Checks that the given object is a complex ordering.

A complex ordering is a data structure consisting of an Array of zero or more attribute names, with the last item in the array a Hash of attribute names and sort directions, e.g. [:title, :author, { publisher: ‘asc’ }].

Parameters:

  • actual (Object)

    The object to match.

Returns:

  • (true, false)

    true if the object matches the expected properties or behavior, otherwise false.



26
27
28
29
30
31
32
33
# File 'lib/cuprum/collections/constraints/order/complex_ordering.rb', line 26

def matches?(actual)
  return false unless actual.is_a?(Array)

  array = actual.dup
  hash  = array.pop

  array_constraint.matches?(array) && hash_constraint.matches?(hash)
end