Sha256: 1797c99634b21edc8215686e513c8cfebe9396d5bb56e5840d8e8981fc9e4de7

Contents?: true

Size: 764 Bytes

Versions: 6

Compression:

Stored size: 764 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 OrderableReverse
    extend ActiveSupport::Concern
    included do
      ## Attributes
      field :_position, type: Float, default: -> {
        (self.class.all.first.try(:_position) || 1000) + 10
      }

      ## Scopes
      default_scope -> { desc(:_position) }

      ## 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_reverse.rb
ants-0.3.13 lib/concerns/ants/orderable_reverse.rb
ants-0.3.12 lib/concerns/ants/orderable_reverse.rb
ants-0.3.11 lib/concerns/ants/orderable_reverse.rb
ants-0.3.10 lib/concerns/ants/orderable_reverse.rb
ants-0.3.9 lib/concerns/ants/orderable_reverse.rb