Class: Cuprum::Collections::Constraints::Order::ComplexOrdering
- Inherits:
-
Stannum::Constraints::Base
- Object
- Stannum::Constraints::Base
- Cuprum::Collections::Constraints::Order::ComplexOrdering
- 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 ⇒ Cuprum::Collections::Constraints::Order::AttributesArray
A cached instance of the constraint with default options.
Instance Method Summary collapse
-
#matches?(actual) ⇒ true, false
(also: #match?)
Checks that the given object is a complex ordering.
Class Method Details
.instance ⇒ Cuprum::Collections::Constraints::Order::AttributesArray
Returns a cached instance of the constraint with default options.
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’ }].
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 |