Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename Dateset method nested_scope to nested

  • Loading branch information...
commit 01bafc748d8bdbb0944e8b5619ec20aefc6d5417 1 parent b2f6767
Paweł Kondzior authored
Showing with 13 additions and 13 deletions.
  1. +12 −12 lib/sequel_nested_set.rb
  2. +1 −1  spec/nested_set_spec.rb
24 lib/sequel_nested_set.rb
View
@@ -58,19 +58,19 @@ def self.apply(model, options = {})
end
module DatasetMethods
- # All nested set queries should use this nested_set_scope, which performs finds on
- # the base ActiveRecord class, using the :scope declared in the acts_as_nested_set
- # declaration.
- def nested_scope
+ # All nested set queries should use this nested, which returns Dataset that provides
+ # proper :scope which you can configure on is :nested, { :scope => ... }
+ # declaration in your Sequel::Model
+ def nested
order(self.model_classes[nil].qualified_left_column)
end
def roots
- nested_scope.filter(self.model_classes[nil].qualified_parent_column => nil)
+ nested.filter(self.model_classes[nil].qualified_parent_column => nil)
end
def leaves
- nested_scope.filter(self.model_classes[nil].qualified_right_column - self.model_classes[nil].qualified_left_column => 1)
+ nested.filter(self.model_classes[nil].qualified_right_column - self.model_classes[nil].qualified_left_column => 1)
end
end
@@ -162,7 +162,7 @@ def root
# Returns the immediate parent
def parent
- dataset.nested_scope.filter(self.primary_key => self.parent_id).first if self.parent_id
+ dataset.nested.filter(self.primary_key => self.parent_id).first if self.parent_id
end
# Returns the dataset for all parent nodes and self
@@ -172,22 +172,22 @@ def self_and_ancestors
# Returns the dataset for all children of the parent, including self
def self_and_siblings
- dataset.nested_scope.filter(self.class.qualified_parent_column => self.parent_id)
+ dataset.nested.filter(self.class.qualified_parent_column => self.parent_id)
end
# Returns dataset for itself and all of its nested children
def self_and_descendants
- dataset.nested_scope.filter((self.class.qualified_left_column >= left) & (self.class.qualified_right_column <= right))
+ dataset.nested.filter((self.class.qualified_left_column >= left) & (self.class.qualified_right_column <= right))
end
# Filter for dataset that will exclude self object
def without_self(dataset)
- dataset.nested_scope.filter(~{self.primary_key => self.id})
+ dataset.nested.filter(~{self.primary_key => self.id})
end
# Returns dataset for its immediate children
def children
- dataset.nested_scope.filter(self.class.qualified_parent_column => self.id)
+ dataset.nested.filter(self.class.qualified_parent_column => self.id)
end
# Returns dataset for all parents
@@ -252,7 +252,7 @@ def to_text
protected
# on creation, set automatically lft and rgt to the end of the tree
def set_default_left_and_right
- maxright = dataset.nested_scopemax(self.class.qualified_right_column) || 0
+ maxright = dataset.nestedmax(self.class.qualified_right_column) || 0
# adds the new node to the right of all existing nodes
self.left = maxright + 1
self.right = maxright + 2
2  spec/nested_set_spec.rb
View
@@ -41,7 +41,7 @@
it "should have all leaves" do
leaves = Client.leaves.all
- leaves.should == Client.nested_scope.filter(:rgt - :lft => 1).all
+ leaves.should == Client.nested.filter(:rgt - :lft => 1).all
leaves.should == [@node1, @node2_1, @node3, @root2]
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.