Sha256: d854ea413c9942c68193371866d4b7ec1082753d39cf85e002dc9503d41897ed

Contents?: true

Size: 754 Bytes

Versions: 18

Compression:

Stored size: 754 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) }

      # helpers
      index({ _position: 1 })


    end
  end
end




Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ants-0.3.5 lib/concerns/ants/orderable.rb
ants-0.3.4 lib/concerns/ants/orderable.rb
ants-0.3.3 lib/concerns/ants/orderable.rb
ants-0.3.2 lib/concerns/ants/orderable.rb
ants-0.3.1 lib/concerns/ants/orderable.rb
ants-0.3.0 lib/concerns/ants/orderable.rb
ants-0.2.8 lib/concerns/ants/orderable.rb
ants-0.2.7 lib/concerns/ants/orderable.rb
ants-0.2.6 lib/concerns/ants/orderable.rb
ants-0.2.5 lib/concerns/ants/orderable.rb
ants-0.2.4 lib/concerns/ants/orderable.rb
ants-0.2.3 lib/concerns/ants/orderable.rb
ants-0.2.2 lib/concerns/ants/orderable.rb
ants-0.2.1 lib/concerns/ants/orderable.rb
ants-0.2.0 lib/concerns/ants/orderable.rb
ants-0.1.4 lib/concerns/ants/orderable.rb
ants-0.1.1 lib/concerns/ants/orderable.rb
ants-0.1.0 lib/concerns/ants/orderable.rb