Sha256: 917193bfc66c987b4f8ccddda635762a1a92cb86179ad31c2776c7ed219aab34

Contents?: true

Size: 516 Bytes

Versions: 26

Compression:

Stored size: 516 Bytes

Contents

module Idx
  extend ActiveSupport::Concern

  included do

    # ------------------------------------------ Scopes

    scope :by_idx, -> { reorder('idx asc') }

    # ------------------------------------------ Callbacks

    after_create :create_idx

  end

  # ------------------------------------------ Instance Methods

  def to_param
    idx.to_s
  end

  def create_idx
    last_obj = self.idx_class.send(self.class.table_name).by_idx.last
    idx = last_obj.idx + 1
    update_columns(:idx => idx)
  end

end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
heartwood-0.0.1 app/models/concerns/idx.rb
cambium-1.3.2 app/models/concerns/idx.rb
cambium-1.3.1 app/models/concerns/idx.rb
cambium-1.3.0 app/models/concerns/idx.rb
cambium-1.2.3 app/models/concerns/idx.rb
cambium-1.2.2 app/models/concerns/idx.rb
cambium-1.2.1 app/models/concerns/idx.rb
cambium-1.2.0 app/models/concerns/idx.rb
cambium-1.1.6 app/models/concerns/idx.rb
cambium-1.1.5 app/models/concerns/idx.rb
cambium-1.1.4 app/models/concerns/idx.rb
cambium-1.1.3 app/models/concerns/idx.rb
cambium-1.1.2 app/models/concerns/idx.rb
cambium-1.1.1 app/models/concerns/idx.rb
cambium-1.1.0 app/models/concerns/idx.rb
cambium-1.0.4 app/models/concerns/idx.rb
cambium-1.0.3 app/models/concerns/idx.rb
cambium-1.0.2 app/models/concerns/idx.rb
cambium-1.0.1 app/models/concerns/idx.rb
cambium-1.0.0 app/models/concerns/idx.rb