Module: Mongoid::Orderable::Mixins::Helpers
- Defined in:
- lib/mongoid/orderable/mixins/helpers.rb
Instance Method Summary collapse
- #default_orderable_field ⇒ Object
- #orderable_bottom(field = nil, in_list = true) ⇒ Object
- #orderable_keys ⇒ Object
- #orderable_scope(field = nil) ⇒ Object
- #orderable_scope_changed?(field) ⇒ Boolean
Instance Method Details
#default_orderable_field ⇒ Object
11 12 13 |
# 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) ⇒ Object
29 30 31 32 33 34 35 |
# 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 ⇒ Object
7 8 9 |
# 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) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/mongoid/orderable/mixins/helpers.rb', line 15 def orderable_scope(field = nil) field ||= default_orderable_field if _parent.send(_association.name).send("orderable_#{field}_scope", self) else orderable_inherited_class.send("orderable_#{field}_scope", self) end end |
#orderable_scope_changed?(field) ⇒ Boolean
25 26 27 |
# File 'lib/mongoid/orderable/mixins/helpers.rb', line 25 def orderable_scope_changed?(field) !orderable_scope(field).where(_id: _id).exists? end |