edge 0.4.4 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -4
- data/CHANGELOG.md +6 -0
- data/edge.gemspec +1 -3
- data/gemfiles/{4.0.gemfile → 5.0.gemfile} +1 -1
- data/lib/edge/forest.rb +32 -39
- data/lib/edge/version.rb +1 -1
- metadata +6 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 156f34d8f9c1f130ba86b2098d2867fff9d53167
|
4
|
+
data.tar.gz: abff9315dd010abfcc006b93ec6533964fb4964d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b35e2189d626e521ac419f03b04dd0aa24d4891b1fd5060d346d83a5c87d97ef727d7fd5fd4a145cd63f0bd6f8671b50b2e089fec2989e05b899e61516cf40e6
|
7
|
+
data.tar.gz: 3fe88512f796388583c763447a79d6e1a09ab21aa732f7f514c8b2406059bf81df5553aeb10503ffaab8c0cb183c4845676bcf8029f03163ffb2ce2cd43cff62
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/edge.gemspec
CHANGED
@@ -15,12 +15,10 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.version = Edge::VERSION
|
17
17
|
|
18
|
-
gem.add_dependency 'activerecord', ">= 4.
|
18
|
+
gem.add_dependency 'activerecord', ">= 4.1.0"
|
19
19
|
|
20
20
|
gem.add_development_dependency 'pg'
|
21
21
|
gem.add_development_dependency 'pry'
|
22
22
|
gem.add_development_dependency 'rake'
|
23
23
|
gem.add_development_dependency 'rspec', "~> 3.1.0"
|
24
|
-
gem.add_development_dependency 'guard', ">= 0.10.0"
|
25
|
-
gem.add_development_dependency 'guard-rspec', ">= 0.6.0"
|
26
24
|
end
|
data/lib/edge/forest.rb
CHANGED
@@ -49,22 +49,14 @@ module Edge
|
|
49
49
|
# # loads all nodes with matching names and all there descendants
|
50
50
|
# Category.where(:name => %w{clothing books electronics}).find_forest
|
51
51
|
def find_forest
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
# statement at different times. If the binds are still '?' then the bind
|
61
|
-
# isn't processed yet. But if it is '$1', '$2', etc. then is has been
|
62
|
-
# processed. This determines how we pass the values to find_by_sql.
|
63
|
-
records = if connection.respond_to? :jdbc_connection_class
|
64
|
-
find_by_sql [manager.to_sql, bind_values.map(&:last)]
|
65
|
-
else
|
66
|
-
find_by_sql manager.to_sql, bind_values
|
67
|
-
end
|
52
|
+
new_scope = unscoped.joins("INNER JOIN all_nodes USING(#{connection.quote_column_name primary_key})")
|
53
|
+
new_scope = new_scope.order(forest_order) if forest_order
|
54
|
+
|
55
|
+
sql = <<-SQL
|
56
|
+
#{cte_sql}
|
57
|
+
#{new_scope.to_sql}
|
58
|
+
SQL
|
59
|
+
records = find_by_sql sql
|
68
60
|
|
69
61
|
records_by_id = records.each_with_object({}) { |r, h| h[r.id] = r }
|
70
62
|
|
@@ -108,32 +100,33 @@ module Edge
|
|
108
100
|
#
|
109
101
|
# Only where scopes can precede this in a scope chain
|
110
102
|
def with_descendants
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
103
|
+
subquery_scope = unscoped
|
104
|
+
.joins("INNER JOIN all_nodes USING(#{connection.quote_column_name primary_key})")
|
105
|
+
.select(primary_key)
|
106
|
+
|
107
|
+
subquery_sql = <<-SQL
|
108
|
+
#{cte_sql}
|
109
|
+
#{subquery_scope.to_sql}
|
110
|
+
SQL
|
111
|
+
|
112
|
+
unscoped.where <<-SQL
|
113
|
+
#{connection.quote_column_name primary_key} IN (#{subquery_sql})
|
114
|
+
SQL
|
115
115
|
end
|
116
116
|
|
117
117
|
private
|
118
|
-
def
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
as_statement = Arel::Nodes::As.new all_nodes, union
|
131
|
-
|
132
|
-
Arel::SelectManager.new(Arel::Table.engine)
|
133
|
-
.with(:recursive, as_statement)
|
134
|
-
.from(all_nodes)
|
135
|
-
.join(arel_table)
|
136
|
-
.on(all_nodes[:id].eq(arel_table[:id]))
|
118
|
+
def cte_sql
|
119
|
+
quoted_table_name = '"locations"'
|
120
|
+
original_scope = (current_scope || all).select(primary_key, forest_foreign_key)
|
121
|
+
iterated_scope = unscoped.select(primary_key, forest_foreign_key)
|
122
|
+
.joins("INNER JOIN all_nodes ON #{connection.quote_column_name table_name}.#{connection.quote_column_name forest_foreign_key}=all_nodes.#{connection.quote_column_name primary_key}")
|
123
|
+
<<-SQL
|
124
|
+
WITH RECURSIVE all_nodes AS (
|
125
|
+
#{original_scope.to_sql}
|
126
|
+
UNION
|
127
|
+
#{iterated_scope.to_sql}
|
128
|
+
)
|
129
|
+
SQL
|
137
130
|
end
|
138
131
|
end
|
139
132
|
|
data/lib/edge/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Christensen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 4.
|
19
|
+
version: 4.1.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 4.
|
26
|
+
version: 4.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pg
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,34 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 3.1.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: guard
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.10.0
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.10.0
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: guard-rspec
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.6.0
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 0.6.0
|
111
83
|
description: Graph functionality for ActiveRecord
|
112
84
|
email:
|
113
85
|
- jack@jackchristensen.com
|
@@ -129,9 +101,9 @@ files:
|
|
129
101
|
- bench/database_structure.sql
|
130
102
|
- bench/forest_find.rb
|
131
103
|
- edge.gemspec
|
132
|
-
- gemfiles/4.0.gemfile
|
133
104
|
- gemfiles/4.1.gemfile
|
134
105
|
- gemfiles/4.2.gemfile
|
106
|
+
- gemfiles/5.0.gemfile
|
135
107
|
- lib/edge.rb
|
136
108
|
- lib/edge/forest.rb
|
137
109
|
- lib/edge/version.rb
|
@@ -164,9 +136,4 @@ signing_key:
|
|
164
136
|
specification_version: 4
|
165
137
|
summary: Graph functionality for ActiveRecord. Provides tree/forest modeling structure
|
166
138
|
that can load entire trees in a single query.
|
167
|
-
test_files:
|
168
|
-
- spec/database.yml
|
169
|
-
- spec/database.yml.travis
|
170
|
-
- spec/database_structure.sql
|
171
|
-
- spec/forest_spec.rb
|
172
|
-
- spec/spec_helper.rb
|
139
|
+
test_files: []
|