Class: Positioning::Healer

Inherits:
Object
  • Object
show all
Defined in:
lib/positioning/healer.rb

Instance Method Summary collapse

Constructor Details

#initialize(model, column, order) ⇒ Healer

Returns a new instance of Healer.



3
4
5
6
7
# File 'lib/positioning/healer.rb', line 3

def initialize(model, column, order)
  @model = model
  @column = column.to_sym
  @order = order
end

Instance Method Details

#healObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/positioning/healer.rb', line 9

def heal
  if scope_columns.present?
    @model.select(*scope_columns).distinct.each do |scope_record|
      @model.transaction do
        if scope_associations.present?
          scope_associations.each do |scope_association|
            scope_record.send(scope_association).lock!
          end
        else
          @model.where(scope_record.slice(*scope_columns)).lock!
        end

        sequence @model.where(scope_record.slice(*scope_columns))
      end
    end
  else
    @model.transaction do
      @model.all.lock!
      sequence @model
    end
  end
end