lib/og/mixin/orderable.rb in og-0.23.0 vs lib/og/mixin/orderable.rb in og-0.24.0
- old
+ new
@@ -1,6 +1,6 @@
-require 'mega/macro'
+require 'mega/dynamod'
module Og
# Attach list/ordering methods to the enchanted class.
@@ -68,10 +68,23 @@
decrement_position_of_lower_items
set_bottom_position
end
end
- def move_to
+ def move_to(dest_position)
+ return if @#{position} == dest_position
+
+ #{base}.transaction do
+ if @#{position} < dest_position
+ #{base}.update("#{position}=(#{position} - 1)", #{cond_and}"#{position} > \#\{@#{position}\} AND #{position} <= \#\{dest_position\}")
+ else
+ #{base}.update("#{position}=(#{position} + 1)", #{cond_and}"#{position} >= \#\{dest_position\} AND #{position} < \#\{@#{position}\} ")
+ end
+ @#{position} = dest_position
+ update_property(:#{position})
+ end
+
+ self
end
def add_to_top
increment_position_of_all_items
end