lib/model_set.rb in ninjudd-model_set-0.10.3 vs lib/model_set.rb in ninjudd-model_set-0.10.4

- old
+ new

@@ -48,11 +48,11 @@ def missing_ids ( @missing_ids || [] ).uniq end - [:add!, :unshift!, :subtract!, :intersect!, :reorder!].each do |action| + [:add!, :unshift!, :subtract!, :intersect!, :reorder!, :reverse_reorder!].each do |action| define_method(action) do |models| anchor!(:set) query.send(action, as_ids(models)) self end @@ -234,24 +234,21 @@ self.clone.sort!(&block) end def sort!(&block) block ||= lambda {|a,b| a <=> b} - self.ids = model_ids.sort do |a,b| - block.call(by_id(a), by_id(b)) - end + sorted_ids = to_a.sort(&block).collect {|m| m.id} + model_ids.reorder!(sorted_ids) self end def sort_by(&block) self.clone.sort_by!(&block) end def sort_by!(&block) - block ||= lambda {|a,b| a <=> b} - self.ids = model_ids.sort_by do |id| - yield by_id(id) - end + sorted_ids = to_a.sort_by(&block).collect {|m| m.id} + model_ids.reorder!(sorted_ids) self end def partition_by(filter) filter = filter.to_s