Sha256: 317243d2f1fc8e969da502d863ed730529d3b2b25a7c7695641a58c9e34090da

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 KB

Contents

require 'awesome_nested_set/tree'

module CollectiveIdea
  module Acts
    module NestedSet
      module Model
        module Rebuildable


          # Rebuilds the left & rights if unset or invalid.
          # Also very useful for converting from acts_as_tree.
          def rebuild!(validate_nodes = true)
            # default_scope with order may break database queries so we do all operation without scope
            unscoped do
              Tree.new(self, validate_nodes).rebuild!
            end
          end

          def scope_for_rebuild
            scope = proc {}

            if acts_as_nested_set_options[:scope]
              scope = proc {|node|
                scope_column_names.inject("") {|str, column_name|
                  column_value = node.send(column_name)
                  cond = column_value.nil? ? "IS NULL" : "= #{connection.quote(column_value)}"
                  str << "AND #{connection.quote_column_name(column_name)} #{cond} "
                }
              }
            end
            scope
          end

          def order_for_rebuild
            "#{quoted_left_column_full_name}, #{quoted_right_column_full_name}, #{primary_key}"
          end
        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
awesome_nested_set-3.1.3 lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.1.2 lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.1.1 lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.1.0 lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.0.3 lib/awesome_nested_set/model/rebuildable.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/awesome_nested_set-3.0.2/lib/awesome_nested_set/model/rebuildable.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/awesome_nested_set-3.0.2/lib/awesome_nested_set/model/rebuildable.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/awesome_nested_set-3.0.2/lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.0.2 lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.0.1 lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.0.0 lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.0.0.rc.6 lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.0.0.rc.5 lib/awesome_nested_set/model/rebuildable.rb
awesome_nested_set-3.0.0.rc.4 lib/awesome_nested_set/model/rebuildable.rb