simple_nested_set 0.0.20 → 0.0.21
Sign up to get free protection for your applications and to get access to all the features.
@@ -54,7 +54,8 @@ module SimpleNestedSet
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def with_leaves
|
57
|
-
where("#{arel_table[:lft].to_sql} = #{arel_table[:rgt].to_sql} - 1").order(:lft)
|
57
|
+
# where("#{arel_table[:lft].to_sql} = #{arel_table[:rgt].to_sql} - 1").order(:lft)
|
58
|
+
where("#{arel_table.name}.lft = #{arel_table.name}.rgt - 1").order(:lft)
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
@@ -122,21 +122,43 @@ module SimpleNestedSet
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def denormalize_level_query
|
125
|
-
query = arel_table.as(:l)
|
126
|
-
query = query.project('count(id)').
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
"level = (#{query.to_sql})"
|
125
|
+
# query = arel_table.as(:l)
|
126
|
+
# query = query.project('count(id)').
|
127
|
+
# where(query[:lft].lt(arel_table[:lft])).
|
128
|
+
# where(query[:rgt].gt(arel_table[:rgt])).
|
129
|
+
# where(where_clauses.map { |clause| clause.gsub(table_name, 'l') })
|
130
|
+
# "level = (#{query.to_sql})"
|
131
|
+
|
132
|
+
%(
|
133
|
+
level = (
|
134
|
+
SELECT COUNT("l"."id")
|
135
|
+
FROM #{table_name} AS l
|
136
|
+
WHERE
|
137
|
+
l.lft < #{table_name}.lft AND
|
138
|
+
l.rgt > #{table_name}.rgt AND
|
139
|
+
#{where_clauses.map { |clause| clause.gsub(table_name, 'l') }.join(' AND ')}
|
140
|
+
)
|
141
|
+
)
|
131
142
|
end
|
132
143
|
|
133
144
|
def denormalize_path_query
|
134
|
-
query = arel_table.as(:l)
|
135
|
-
query = query.project(group_concat(db_adapter, :slug)).
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
"path = (#{query.to_sql})"
|
145
|
+
# query = arel_table.as(:l)
|
146
|
+
# query = query.project(group_concat(db_adapter, :slug)).
|
147
|
+
# where(query[:lft].lteq(arel_table[:lft])).
|
148
|
+
# where(query[:rgt].gteq(arel_table[:rgt])).
|
149
|
+
# where(where_clauses.map { |clause| clause.gsub(table_name, 'l') })
|
150
|
+
# "path = (#{query.to_sql})"
|
151
|
+
|
152
|
+
%(
|
153
|
+
path = (
|
154
|
+
SELECT #{group_concat(db_adapter, :slug)}
|
155
|
+
FROM #{table_name} AS l
|
156
|
+
WHERE
|
157
|
+
l.lft <= #{table_name}.lft AND
|
158
|
+
l.rgt >= #{table_name}.rgt AND
|
159
|
+
#{where_clauses.map { |clause| clause.gsub(table_name, 'l') }.join(' AND ')}
|
160
|
+
)
|
161
|
+
)
|
140
162
|
end
|
141
163
|
|
142
164
|
def db_adapter
|
@@ -1,68 +1,100 @@
|
|
1
1
|
require 'gem_patching'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
3
|
+
if Arel::VERSION == '1.0.1'
|
4
|
+
Gem.patching('arel', '1.0.1') do
|
5
|
+
# Arel 1.0.0.rc1 Arel::Table#initialize and #table_exists? does not support
|
6
|
+
# instantiating an Arel::Table before the database table has been created.
|
7
|
+
#
|
8
|
+
# This happens in adva-cms2 during the setup of the cucumber test application
|
9
|
+
# where the environment has to be loaded (and thus models will be loaded) and
|
10
|
+
# migrations will only be run afterwards.
|
11
|
+
#
|
12
|
+
# see http://github.com/rails/arel/commit/19c5a95f1093653d2628dfb2f53637b0425dbba4#commitcomment-133903
|
13
|
+
#
|
14
|
+
# Also, in Arel 1.0.0.rc1 Arel::Table#initialize @options won't be initialized
|
15
|
+
# if the second argument is an engine, so #as will crash subsequently.
|
16
|
+
#
|
17
|
+
# These issues have been fixed in:
|
18
|
+
#
|
19
|
+
# http://github.com/svenfuchs/arel/commit/4b476404cbbecfedc255039c66c6eececb667d7f
|
20
|
+
# http://github.com/svenfuchs/arel/commit/3b1b24551106bc116cba404c992b513c5fbd137b
|
21
|
+
Arel::Table.class_eval do
|
22
|
+
def initialize(name, options = {})
|
23
|
+
@name = name.to_s
|
24
|
+
@table_exists = nil
|
25
|
+
@table_alias = nil
|
26
|
+
@christener = Arel::Sql::Christener.new
|
27
|
+
@attributes = nil
|
28
|
+
@matching_attributes = nil
|
19
29
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@name = name.to_s
|
24
|
-
@table_exists = nil
|
25
|
-
@table_alias = nil
|
26
|
-
@christener = Arel::Sql::Christener.new
|
27
|
-
@attributes = nil
|
28
|
-
@matching_attributes = nil
|
30
|
+
if options.is_a?(Hash)
|
31
|
+
@options = options
|
32
|
+
@engine = options[:engine] || Arel::Table.engine
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@
|
34
|
+
if options[:as]
|
35
|
+
as = options[:as].to_s
|
36
|
+
@table_alias = as unless as == @name
|
37
|
+
end
|
38
|
+
else
|
39
|
+
@engine = options # Table.new('foo', engine)
|
40
|
+
@options = {}
|
37
41
|
end
|
38
|
-
else
|
39
|
-
@engine = options # Table.new('foo', engine)
|
40
|
-
@options = {}
|
41
|
-
end
|
42
42
|
|
43
|
-
|
44
|
-
begin
|
45
|
-
require "arel/engines/sql/compilers/#{@engine.adapter_name.downcase}_compiler"
|
46
|
-
rescue LoadError
|
43
|
+
if @engine.connection
|
47
44
|
begin
|
48
|
-
|
49
|
-
require "#{@engine.adapter_name.downcase}/arel_compiler"
|
45
|
+
require "arel/engines/sql/compilers/#{@engine.adapter_name.downcase}_compiler"
|
50
46
|
rescue LoadError
|
51
|
-
|
47
|
+
begin
|
48
|
+
# try to load an externally defined compiler, in case this adapter has defined the compiler on its own.
|
49
|
+
require "#{@engine.adapter_name.downcase}/arel_compiler"
|
50
|
+
rescue LoadError
|
51
|
+
raise "#{@engine.adapter_name} is not supported by Arel."
|
52
|
+
end
|
52
53
|
end
|
54
|
+
|
55
|
+
@@tables ||= engine.connection.tables
|
53
56
|
end
|
57
|
+
end
|
54
58
|
|
55
|
-
|
59
|
+
def as(table_alias)
|
60
|
+
@options ||= {}
|
61
|
+
Arel::Table.new(name, options.merge(:as => table_alias))
|
56
62
|
end
|
57
|
-
end
|
58
63
|
|
59
|
-
|
60
|
-
|
61
|
-
|
64
|
+
def table_exists?
|
65
|
+
@table_exists ||= @@tables.include?(name) || engine.connection.table_exists?(name)
|
66
|
+
end
|
62
67
|
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
Gem.patching('arel', '2.0.4') do
|
71
|
+
Arel::Table.class_eval do
|
72
|
+
attr_reader :options
|
73
|
+
|
74
|
+
def initialize name, engine = Arel::Table.engine
|
75
|
+
@name = name.to_s
|
76
|
+
@engine = engine
|
77
|
+
@columns = nil
|
78
|
+
@aliases = []
|
79
|
+
@table_alias = nil
|
80
|
+
@primary_key = nil
|
63
81
|
|
64
|
-
|
65
|
-
|
82
|
+
if Hash === engine
|
83
|
+
@options = engine
|
84
|
+
@engine = engine[:engine] || Arel::Table.engine
|
85
|
+
@columns = attributes_for engine[:columns]
|
86
|
+
|
87
|
+
# Sometime AR sends an :as parameter to table, to let the table know
|
88
|
+
# that it is an Alias. We may want to override new, and return a
|
89
|
+
# TableAlias node?
|
90
|
+
@table_alias = engine[:as] unless engine[:as].to_s == @name
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def as(table_alias)
|
95
|
+
@options ||= {}
|
96
|
+
Arel::Table.new(name, options.merge(:as => table_alias))
|
97
|
+
end
|
66
98
|
end
|
67
99
|
end
|
68
100
|
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: 53
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 21
|
10
|
+
version: 0.0.21
|
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-11-
|
18
|
+
date: 2010-11-20 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,16 +26,16 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 1
|
30
30
|
segments:
|
31
31
|
- 3
|
32
32
|
- 0
|
33
|
-
-
|
34
|
-
version: 3.0.
|
33
|
+
- 3
|
34
|
+
version: 3.0.3
|
35
35
|
type: :runtime
|
36
36
|
version_requirements: *id001
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
38
|
+
name: gem_patching
|
39
39
|
prerelease: false
|
40
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
type: :runtime
|
50
50
|
version_requirements: *id002
|
51
51
|
- !ruby/object:Gem::Dependency
|
52
|
-
name:
|
52
|
+
name: test_declarative
|
53
53
|
prerelease: false
|
54
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
55
|
none: false
|
@@ -60,10 +60,10 @@ dependencies:
|
|
60
60
|
segments:
|
61
61
|
- 0
|
62
62
|
version: "0"
|
63
|
-
type: :
|
63
|
+
type: :development
|
64
64
|
version_requirements: *id003
|
65
65
|
- !ruby/object:Gem::Dependency
|
66
|
-
name:
|
66
|
+
name: sqlite3-ruby
|
67
67
|
prerelease: false
|
68
68
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
69
|
none: false
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
type: :development
|
78
78
|
version_requirements: *id004
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
|
-
name:
|
80
|
+
name: database_cleaner
|
81
81
|
prerelease: false
|
82
82
|
requirement: &id005 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
@@ -91,7 +91,7 @@ dependencies:
|
|
91
91
|
type: :development
|
92
92
|
version_requirements: *id005
|
93
93
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
94
|
+
name: ruby-debug
|
95
95
|
prerelease: false
|
96
96
|
requirement: &id006 !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
@@ -104,20 +104,6 @@ dependencies:
|
|
104
104
|
version: "0"
|
105
105
|
type: :development
|
106
106
|
version_requirements: *id006
|
107
|
-
- !ruby/object:Gem::Dependency
|
108
|
-
name: ruby-debug
|
109
|
-
prerelease: false
|
110
|
-
requirement: &id007 !ruby/object:Gem::Requirement
|
111
|
-
none: false
|
112
|
-
requirements:
|
113
|
-
- - ">="
|
114
|
-
- !ruby/object:Gem::Version
|
115
|
-
hash: 3
|
116
|
-
segments:
|
117
|
-
- 0
|
118
|
-
version: "0"
|
119
|
-
type: :development
|
120
|
-
version_requirements: *id007
|
121
107
|
description: simple_nested_set allows to easily handle nested sets in ActiveRecord
|
122
108
|
email: svenfuchs@artweb-design.de
|
123
109
|
executables: []
|