# File lib/cursor_pager/order_value.rb, line 33 def primary_key? relation.primary_key == attribute end
class CursorPager::OrderValue
Wraps ActiveRecord's order values. Depending on how the order of the relation is defined, ActiveRecord will give you multiple arel nodes or just one string. This deals with the differences so we don't have to do it anywhere else.
Constants
- PARENTHESIS_REGEX
Attributes
attribute[R]
direction[R]
relation[R]
Public Class Methods
from_arel_node(relation, node)
click to toggle source
# File lib/cursor_pager/order_value.rb, line 13 def self.from_arel_node(relation, node) new(relation, node.value.name, node.direction) end
from_order_string(relation, value)
click to toggle source
# File lib/cursor_pager/order_value.rb, line 17 def self.from_order_string(relation, value) if value.match?(PARENTHESIS_REGEX) raise OrderValueError, "Order values can't include functions." end value.split(",").map do |split_value| new(relation, *split_value.squish.split) end end
new(relation, attribute, direction = :asc)
click to toggle source
# File lib/cursor_pager/order_value.rb, line 27 def initialize(relation, attribute, direction = :asc) @relation = relation @attribute = attribute @direction = direction.downcase.to_sym end
Public Instance Methods
order_string()
click to toggle source
# File lib/cursor_pager/order_value.rb, line 55 def order_string "#{prefixed_attribute} #{direction}" end
prefixed_attribute()
click to toggle source
# File lib/cursor_pager/order_value.rb, line 41 def prefixed_attribute return attribute if attribute.include?(".") "#{relation.table_name}.#{attribute}" end
primary_key?()
click to toggle source
select_alias()
click to toggle source
# File lib/cursor_pager/order_value.rb, line 47 def select_alias prefixed_attribute.tr(".", "_") end
select_string()
click to toggle source
# File lib/cursor_pager/order_value.rb, line 51 def select_string "#{prefixed_attribute} AS #{select_alias}" end
type()
click to toggle source
# File lib/cursor_pager/order_value.rb, line 37 def type relation.type_for_attribute(attribute).type end