Sha256: 4861a33e4b450ba9619d34cbe829166fabe04513c9623f7019889ba70e014ec7

Contents?: true

Size: 750 Bytes

Versions: 6

Compression:

Stored size: 750 Bytes

Contents

# =============================================================================
# IMPORTANT: this default value raises "stack level too deep" if concern is
#            included for existing objects, to fix issue update _position
#            value for all objects like this:
#
#            > ModelClass.all.set(_position: 1000)
# =============================================================================
module Ants
  module Orderable
    extend ActiveSupport::Concern
    included do
      ## Attributes
      field :_position, type: Float, default: -> { (self.class.all.last.try(:_position) || 1000) + 10 }

      ## Scopes
      default_scope -> { order_by(_position: :asc) }

      ## Indexes
      index({ _position: 1 })
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ants-0.3.14 lib/concerns/ants/orderable.rb
ants-0.3.13 lib/concerns/ants/orderable.rb
ants-0.3.12 lib/concerns/ants/orderable.rb
ants-0.3.11 lib/concerns/ants/orderable.rb
ants-0.3.10 lib/concerns/ants/orderable.rb
ants-0.3.9 lib/concerns/ants/orderable.rb