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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbe295739f4d8428d51ab51caaf1ea299388ff1a
4
- data.tar.gz: 05b0a917146b57191b1a0accc561a90ee457df38
3
+ metadata.gz: 156f34d8f9c1f130ba86b2098d2867fff9d53167
4
+ data.tar.gz: abff9315dd010abfcc006b93ec6533964fb4964d
5
5
  SHA512:
6
- metadata.gz: ad2b80707a647c3dadf1bb06b60ca5f4b002b56f5ac9577cbed2c353ab2a08fcf6fa3042999ae07958cc06b6c11a67cd5b2c66ebce5783bbd9336282ee8d235e
7
- data.tar.gz: 46942d09d2066d6bf901146d3d8d86eb38d341aaa598c77cd57758a5538278e5159f992e62e9981769ccbf16e8bbd809874c1f9c2abdfd1f53e24f0be724ae1b
6
+ metadata.gz: b35e2189d626e521ac419f03b04dd0aa24d4891b1fd5060d346d83a5c87d97ef727d7fd5fd4a145cd63f0bd6f8671b50b2e089fec2989e05b899e61516cf40e6
7
+ data.tar.gz: 3fe88512f796388583c763447a79d6e1a09ab21aa732f7f514c8b2406059bf81df5553aeb10503ffaab8c0cb183c4845676bcf8029f03163ffb2ce2cd43cff62
data/.travis.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
4
- - 2.1.5
5
- - 2.0.0
3
+ - 2.3.1
4
+ - 2.2.5
5
+ - 2.1.9
6
6
  gemfile:
7
- - gemfiles/4.0.gemfile
8
7
  - gemfiles/4.1.gemfile
9
8
  - gemfiles/4.2.gemfile
9
+ - gemfiles/5.0.gemfile
10
10
 
11
11
  addons:
12
12
  postgresql: "9.2"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 0.5.0 (May 14, 2016)
2
+
3
+ * Add Rails 5.0 support
4
+ * Drop Rails 4.0 support
5
+ * Replace using internal arel with SQL string building
6
+
1
7
  # 0.4.4 (January 29, 2016)
2
8
 
3
9
  * Fix JRuby compatibility (jackc)
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.0.0"
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
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activerecord", "4.0.13"
3
+ gem "activerecord", "~> 5.0.0.rc1"
4
4
 
5
5
  gemspec :path=>"../"
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
- manager = recursive_manager.project(Arel.star)
53
- manager.order(forest_order) if forest_order
54
-
55
- bind_values = current_scope ? current_scope.bind_values : []
56
-
57
- # This is a nasty hack to work around
58
- # https://github.com/jackc/edge/issues/14 The MRI pg gem and the JRuby
59
- # activerecord-jdbcpostgresql-adapter gem bind values into the prepared
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
- manager = recursive_manager.project(arel_table[:id])
112
- scope = unscoped.where(arel_table[:id].in manager)
113
- scope.bind_values = current_scope.bind_values if current_scope
114
- scope
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 recursive_manager
119
- all_nodes = Arel::Table.new(:all_nodes)
120
-
121
- original_term = (current_scope || all).select(primary_key, forest_foreign_key).arel
122
- iterated_term = Arel::SelectManager.new Arel::Table.engine
123
- iterated_term.from(arel_table)
124
- .project([arel_table[primary_key.to_sym], arel_table[forest_foreign_key.to_sym]])
125
- .join(all_nodes)
126
- .on(arel_table[forest_foreign_key].eq all_nodes[:id])
127
-
128
- union = original_term.union(iterated_term)
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
@@ -1,3 +1,3 @@
1
1
  module Edge
2
- VERSION = "0.4.4"
2
+ VERSION = "0.5.0"
3
3
  end
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.4
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-01-29 00:00:00.000000000 Z
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.0.0
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.0.0
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: []