Module: OrderAlready::InputOrderSerializer

Defined in:
lib/order_already.rb

Overview

This serializer preserves the input order regardless of underlying persistence order.

The two public methods are InputOrderSerializer.deserialize and InputOrderSerializer.serialize.

Constant Summary collapse

TOKEN_DELIMITER =
'~'

Class Method Summary collapse

Class Method Details

.deserialize(arr) ⇒ Array

Convert a serialized array to a normal array of values.

Parameters:

  • arr (Array)

Returns:

  • (Array)


83
84
85
86
87
88
89
90
91
# File 'lib/order_already.rb', line 83

def self.deserialize(arr)
  arr = arr&.compact || []
  arr = arr.reject(&:empty?)
  return [] if arr.empty?

  sort(arr).map do |val|
    get_value(val)
  end
end

.relation_to_array(arr) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

convert an ActiveTriples::Relation to a standard array (for debugging)



167
168
169
# File 'lib/order_already.rb', line 167

def self.relation_to_array(arr)
  arr.map(&:to_s)
end

.serialize(arr) ⇒ Array

Serialize a normal array of values to an array of ordered values

Parameters:

  • arr (Array)

Returns:

  • (Array)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/order_already.rb', line 99

def self.serialize(arr)
  arr = arr&.compact || []
  arr = arr.reject(&:empty?)
  return [] if arr.empty?

  arr = sanitize(arr)

  res = []
  arr.each_with_index do |val, ix|
    res << encode(ix, val)
  end

  res
end