Sha256: 277f39841136098117273ba0c1ad7090db66fe187a00405b3e8617b4e1b434ba
Contents?: true
Size: 742 Bytes
Versions: 9
Compression:
Stored size: 742 Bytes
Contents
module CloudSesame module Query module Node class Sort < Abstract attr_reader :sorting_attributes def sorting_attributes @sorting_attributes ||= deserialize context[:sort] end def [](attribute) sorting_attributes[attribute.to_sym] end def []=(attribute, order = :desc) sorting_attributes[attribute.to_sym] = order.to_sym if order end def compile (result = serialize(sorting_attributes)).empty? ? {} : { sort: result } end private def serialize(hash = {}) hash.to_a.map { |i| i.join(' ') }.join(',') end def deserialize(string) Hash[*((string || "").split(',').map { |i| i.strip.split(' ').map(&:to_sym) }.flatten)] end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems