module Para::Orderable

Private Instance Methods

orderable_assign_position() click to toggle source
# File lib/para/orderable.rb, line 15
def orderable_assign_position
  return if attribute_present?(:position)

  last_resource = orderable_scope
    .where.not(position: nil)
    .select(:position)
    .first

  self.position = if last_resource && last_resource.position
    last_resource.position + 1
  else
    0
  end
end
orderable_scope() click to toggle source
# File lib/para/orderable.rb, line 38
def orderable_scope
  if (parent = _orderable_options[:parent]) && (as = _orderable_options[:as])
    try(parent).try(as).try(:ordered) || self.class.none
  else
    self.class.unscoped.ordered
  end
end
reprocess_ordering() click to toggle source

Unfragment existing resources positions

# File lib/para/orderable.rb, line 32
def reprocess_ordering
  orderable_scope.each_with_index do |resource, index|
    resource.update_column(:position, index)
  end
end