simple_nested_set 0.0.27 → 0.0.28
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.
@@ -1,19 +1,27 @@
|
|
1
1
|
module SimpleNestedSet
|
2
2
|
module Rebuild
|
3
3
|
class FromParents
|
4
|
-
|
4
|
+
include SqlAbstraction
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
attr_accessor :num
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@num = 0
|
8
10
|
end
|
9
11
|
|
10
12
|
def run(nested_set, sort_order = nil)
|
11
|
-
order_columns = ([:parent_id] + Array[sort_order]).compact
|
13
|
+
order_columns = ([:parent_id] + Array[sort_order]).uniq.compact
|
14
|
+
|
15
|
+
db_adapter = nested_set.first.class.connection.instance_variable_get('@config')[:adapter].to_sym
|
16
|
+
|
17
|
+
order_clause = order_columns.map do |col|
|
18
|
+
order_by(db_adapter, col)
|
19
|
+
end
|
12
20
|
|
13
21
|
nodes = if nested_set.respond_to?(:except)
|
14
|
-
nested_set.except(:order).order(
|
22
|
+
nested_set.except(:order).order(order_clause)
|
15
23
|
else
|
16
|
-
nested_set.reorder(
|
24
|
+
nested_set.reorder(order_clause)
|
17
25
|
end.to_a
|
18
26
|
|
19
27
|
renumber(nodes.dup)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SimpleNestedSet
|
2
|
+
# database-specific statements, ready to be
|
3
|
+
# inserted into arel.project()
|
2
4
|
module SqlAbstraction
|
3
|
-
# return a database-specific 'GROUP_CONCAT'-statement, ready to be
|
4
|
-
# inserted into arel.project()
|
5
5
|
def group_concat(database, field, separator = '/')
|
6
6
|
case database.to_sym
|
7
7
|
when :sqlite, :sqlite3
|
@@ -14,5 +14,16 @@ module SimpleNestedSet
|
|
14
14
|
raise ArgumentError, "#{database} is not supported by SimpleNestedSet::SqlAbstraction#group_concat"
|
15
15
|
end
|
16
16
|
end
|
17
|
+
|
18
|
+
def order_by(database, order)
|
19
|
+
case database.to_sym
|
20
|
+
when :sqlite, :sqlite3
|
21
|
+
order.to_s
|
22
|
+
when :mysql, :mysql2
|
23
|
+
"`#{order }`"
|
24
|
+
when :postgresql
|
25
|
+
"\"#{order}\" NULLS FIRST"
|
26
|
+
end
|
27
|
+
end
|
17
28
|
end
|
18
29
|
end
|
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:
|
4
|
+
hash: 39
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 28
|
10
|
+
version: 0.0.28
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Sven Fuchs
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-13 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|