simple_nested_set 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,14 @@ module SimpleNestedSet
|
|
10
10
|
set_callback(:move, :after, *args, &block)
|
11
11
|
end
|
12
12
|
|
13
|
+
# Returns all roots recursively pre-populated with their children associations
|
14
|
+
def trees(scope = nil)
|
15
|
+
nodes = nested_set_class.scope(scope)
|
16
|
+
nodes.select(&:root?).each do |root|
|
17
|
+
root.nested_set.populate_associations(nodes.select { |node| node.descendent_of?(root) })
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
13
21
|
# Returns the first root node (with the given scope if any)
|
14
22
|
def root(scope = nil)
|
15
23
|
roots(scope).first
|
@@ -15,12 +15,12 @@ module SimpleNestedSet
|
|
15
15
|
super(attributes, *args)
|
16
16
|
end
|
17
17
|
|
18
|
-
#
|
19
|
-
|
20
|
-
def load_tree
|
18
|
+
# Returns self with the children association recursively pre-populated
|
19
|
+
def as_tree
|
21
20
|
nested_set.populate_associations(descendants)
|
22
21
|
self
|
23
22
|
end
|
23
|
+
alias :load_tree :as_tree
|
24
24
|
|
25
25
|
# Returns true if this is a root node.
|
26
26
|
def root?
|
@@ -73,26 +73,10 @@ when /^2\.0\.[5-9]$/, /^2\.1\.[01]$/, '2.0.10'
|
|
73
73
|
attr_reader :options # this line is added
|
74
74
|
|
75
75
|
def initialize name, engine = Arel::Table.engine
|
76
|
-
@
|
77
|
-
|
78
|
-
@columns = nil
|
79
|
-
@aliases = []
|
80
|
-
@table_alias = nil
|
81
|
-
@primary_key = nil
|
82
|
-
|
83
|
-
if Hash === engine
|
84
|
-
@options = engine # this line is added
|
85
|
-
@engine = engine[:engine] || Arel::Table.engine
|
86
|
-
@columns = attributes_for engine[:columns]
|
87
|
-
|
88
|
-
# Sometime AR sends an :as parameter to table, to let the table know
|
89
|
-
# that it is an Alias. We may want to override new, and return a
|
90
|
-
# TableAlias node?
|
91
|
-
@table_alias = engine[:as] unless engine[:as].to_s == @name
|
92
|
-
end
|
76
|
+
@options = engine if Hash === engine
|
77
|
+
super
|
93
78
|
end
|
94
79
|
|
95
|
-
# this whole method is added
|
96
80
|
def as(table_alias)
|
97
81
|
@options ||= {}
|
98
82
|
Arel::Table.new(name, options.merge(:as => table_alias))
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_nested_set
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sven Fuchs
|
@@ -16,8 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-05-
|
20
|
-
default_executable:
|
19
|
+
date: 2011-05-20 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
22
|
name: activerecord
|
@@ -176,7 +175,6 @@ files:
|
|
176
175
|
- lib/simple_nested_set/sql_abstraction.rb
|
177
176
|
- lib/simple_nested_set/version.rb
|
178
177
|
- lib/simple_nested_set.rb
|
179
|
-
has_rdoc: true
|
180
178
|
homepage: http://github.com/svenfuchs/simple_nested_set
|
181
179
|
licenses: []
|
182
180
|
|
@@ -206,9 +204,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
204
|
requirements: []
|
207
205
|
|
208
206
|
rubyforge_project: "[none]"
|
209
|
-
rubygems_version: 1.
|
207
|
+
rubygems_version: 1.7.2
|
210
208
|
signing_key:
|
211
209
|
specification_version: 3
|
212
210
|
summary: a simple to use nested set solution for ActiveRecord 3
|
213
211
|
test_files: []
|
214
212
|
|
213
|
+
has_rdoc:
|