class Cuprum::Collections::Constraints::Order::ComplexOrdering
Asserts that the object is an attributes Array with an sort order Hash.
Public Class Methods
instance()
click to toggle source
@return [Cuprum::Collections::Constraints::Order::AttributesArray] a
cached instance of the constraint with default options.
# File lib/cuprum/collections/constraints/order/complex_ordering.rb, line 12 def self.instance @instance ||= new end
Public Instance Methods
matches?(actual)
click to toggle source
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’ }].
@param actual [Object] The object to match.
@return [true, false] true if the object matches the expected properties
or behavior, otherwise false.
# 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
Also aliased as: match?
Private Instance Methods
array_constraint()
click to toggle source
# File lib/cuprum/collections/constraints/order/complex_ordering.rb, line 38 def array_constraint Cuprum::Collections::Constraints::Order::AttributesArray.instance end
hash_constraint()
click to toggle source
# File lib/cuprum/collections/constraints/order/complex_ordering.rb, line 42 def hash_constraint Cuprum::Collections::Constraints::Order::AttributesHash.instance end