Sha256: 00f2d68301be33209426370f32833a4c03a098fd3989e3c71b14d156721adf76

Contents?: true

Size: 598 Bytes

Versions: 9

Compression:

Stored size: 598 Bytes

Contents

module Callbacks
  class ViewableAfterDestroy
    include Restrictor

    def init
      @range = (m.position + 1)..Float::INFINITY
    end

    def call
      update_list
      m.other_locales.each do |viewable|
        viewable.destroy!
        update_list(viewable.locale)
      end
    end

    private

    def update_list(locale = nil)
      query = m.list(locale).where(unique_keys: { position: @range }).order('unique_keys.position')

      query.each.with_index(m.position) do |viewable, position|
        viewable.unique_key.update_column(:position, position)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rails_admin_cms-0.1.1 app/models/callbacks/viewable_after_destroy.rb
rails_admin_cms-0.0.9 app/models/callbacks/viewable_after_destroy.rb
rails_admin_cms-0.0.7 app/models/callbacks/viewable_after_destroy.rb
rails_admin_cms-0.0.6 app/models/callbacks/viewable_after_destroy.rb
rails_admin_cms-0.0.5 app/models/callbacks/viewable_after_destroy.rb
rails_admin_cms-0.0.4 app/models/callbacks/viewable_after_destroy.rb
rails_admin_cms-0.0.3 app/models/callbacks/viewable_after_destroy.rb
rails_admin_cms-0.0.2 app/models/callbacks/viewable_after_destroy.rb
rails_admin_cms-0.0.1 app/models/callbacks/viewable_after_destroy.rb