Sha256: abea9e34297c64d522cd0c0ded1db4c44437cf2d329526cb60037504d9228719

Contents?: true

Size: 825 Bytes

Versions: 41

Compression:

Stored size: 825 Bytes

Contents

module Positionable
  extend ActiveSupport::Concern
  
  MAX_POS = 32768 # maximum 2 bytes integer
  
  included do
    field :position, :integer, :default => MAX_POS
  end

  module ClassMethods
    def update_positions(id_pos_pairs)
      self.transaction do
        id_pos_pairs.each do |pair|
          self.find(pair[:id]).update_attributes!(:position => pair[:position])
        end
      end
    end
  end


  class << self
    
    def get(class_name)
      @_positionable_flyweight ||= {}
      underscored_name = class_name.is_a?(Class) ? class_name.name.underscore : class_name.to_s.underscore.singularize
      @_positionable_flyweight[underscored_name] || (@_positionable_flyweight[underscored_name] = class_name.is_a?(Class) ? class_name : "#{underscored_name}".camelize.constantize)
    end
        
  end

end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
fullstack-admin-0.2.26 app/models/positionable.rb
fullstack-admin-0.2.25 app/models/positionable.rb
fullstack-admin-0.2.24 app/models/positionable.rb
fullstack-admin-0.2.23 app/models/positionable.rb
fullstack-admin-0.2.22 app/models/positionable.rb
fullstack-admin-0.2.21 app/models/positionable.rb
fullstack-admin-0.2.20 app/models/positionable.rb
fullstack-admin-0.2.19 app/models/positionable.rb
fullstack-admin-0.2.18 app/models/positionable.rb
fullstack-admin-0.2.17 app/models/positionable.rb
fullstack-admin-0.2.16 app/models/positionable.rb
fullstack-admin-0.2.15 app/models/positionable.rb
fullstack-admin-0.2.14 app/models/positionable.rb
fullstack-admin-0.2.13 app/models/positionable.rb
fullstack-admin-0.2.12 app/models/positionable.rb
fullstack-admin-0.2.11 app/models/positionable.rb
fullstack-admin-0.2.9 app/models/positionable.rb
fullstack-admin-0.2.8 app/models/positionable.rb
fullstack-admin-0.2.7 app/models/positionable.rb
fullstack-admin-0.2.6 app/models/positionable.rb