module Mongoid::Orderable::Mixins::Helpers
Public Instance Methods
default_orderable_field()
click to toggle source
# File lib/mongoid/orderable/mixins/helpers.rb, line 11 def default_orderable_field self.class.orderable_configs.detect {|_c, conf| conf[:default] }.try(:first) || orderable_keys.first end
orderable_bottom(field = nil, in_list = true)
click to toggle source
# File lib/mongoid/orderable/mixins/helpers.rb, line 29 def orderable_bottom(field = nil, in_list = true) field ||= default_orderable_field f = orderable_field(field) max = orderable_scope(field).ne(f => nil).max(f) return orderable_top(field) unless max in_list ? max : max.next end
orderable_keys()
click to toggle source
# File lib/mongoid/orderable/mixins/helpers.rb, line 7 def orderable_keys Array(orderable_inherited_class.orderable_configs.try(:keys)) end
orderable_scope(field = nil)
click to toggle source
# File lib/mongoid/orderable/mixins/helpers.rb, line 15 def orderable_scope(field = nil) field ||= default_orderable_field if embedded? _parent.send(_association.name).send("orderable_#{field}_scope", self) else orderable_inherited_class.send("orderable_#{field}_scope", self) end end
orderable_scope_changed?(field)
click to toggle source
# File lib/mongoid/orderable/mixins/helpers.rb, line 25 def orderable_scope_changed?(field) !orderable_scope(field).where(_id: _id).exists? end