Module: Oort::Ordered::ClassMethods

Defined in:
lib/oort/ordered.rb

Instance Method Summary collapse

Instance Method Details

#handles_ordering_of(association, default: :top) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/oort/ordered.rb', line 13

def handles_ordering_of(association, default: :top)
  args = {
    stored_in: :"#{association}_ordering",
    insert_method_name: :"update_#{association}_ordering",
    remove_from_method_name: :"remove_from_#{association}_ordering",
    association_class: association.to_s.classify.constantize,
    instance_name: :"#{name.downcase}",
    class_name: name.classify.constantize,
    default:
  }

  Inserts.call(**args.slice(:stored_in, :insert_method_name, :class_name))
  Removes.call(**args.slice(:stored_in, :remove_from_method_name, :class_name))
  Callbacks.call(
    **args.slice(:association_class, :remove_from_method_name, :insert_method_name, :instance_name, :default)
  )
end