Sha256: 004da45176f035353286592c6bd208f383a6ea39d6ad896ea1f0deb74c8324ae
Contents?: true
Size: 522 Bytes
Versions: 27
Compression:
Stored size: 522 Bytes
Contents
# frozen_string_literal: true class ChildDoc include Mongoid::Document embedded_in :parent_doc attr_writer :position after_save :update_position def position existing_position = parent_doc.children_order.index(id) existing_position ? existing_position + 1 : parent_doc.aspects.size end def update_position if @position && (@position.to_i > 0) parent_doc.children_order.delete(id) parent_doc.children_order.insert(@position.to_i - 1, id) parent_doc.save! end end end
Version data entries
27 entries across 27 versions & 1 rubygems