edge 0.2.1 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c25599a81a0c7af695a8155fda82079ab4bb21d5
4
- data.tar.gz: d870f4eb3cf382ca5e1e828da2a5b1235939a44e
3
+ metadata.gz: c44e87734aaa9f415d1fd27dae95c877c975ef0c
4
+ data.tar.gz: 5339eb867e7383ada9fc7677f89c84eceaa4844a
5
5
  SHA512:
6
- metadata.gz: 7528d8b4bf34d7bd2f93cead42b34290b3bce459975d885a32e35e6e9ebc4d27440492e7b3a01e66c85ee2a278a5ab20db68dab7d41321cf10724a636a3e5541
7
- data.tar.gz: cf043a89a0b47ba43a49270403acef578313cd618b0efc73b79c0f6f0f7e11aee5c0952d1a5705f4d381be081737b894c57fe67f8aa3f4d8ec7bdb2986da6d0e
6
+ metadata.gz: ce618003724c04a238a18c9f786ebf312f8212da8482ea5b6f1ab5875f61e48a110f0bf4a83a203810a9d71e128cb4dde2e0c4fe6e520f53d82734f1a5e083b1
7
+ data.tar.gz: 3f324365418e1dbaea369b0806ff1a9d173947018abc45fa13fad78bcd9b985c060834d768973ef2c9e18b541ccce9494effca947f0e3ce933d7dc1679122939
@@ -1,3 +1,8 @@
1
+ # 0.3.0 (December 17, 2013)
2
+
3
+ * Rails 4 support
4
+ * Fix for incomparable column types
5
+
1
6
  # 0.2.1 (March 6, 2013)
2
7
 
3
8
  * Fix: acts_as_forest survives multiple calls
@@ -14,11 +14,12 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "edge"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Edge::VERSION
17
-
17
+
18
18
  gem.add_dependency 'activerecord', ">= 3.2.0"
19
-
19
+
20
20
  gem.add_development_dependency 'pg'
21
+ gem.add_development_dependency 'pry'
21
22
  gem.add_development_dependency 'rspec', "~> 2.8.0"
22
23
  gem.add_development_dependency 'guard', ">= 0.10.0"
23
- gem.add_development_dependency 'guard-rspec', ">= 0.6.0"
24
+ gem.add_development_dependency 'guard-rspec', ">= 0.6.0"
24
25
  end
@@ -22,15 +22,13 @@ module Edge
22
22
 
23
23
  belongs_to :parent, common_options
24
24
 
25
- children_options = if forest_order
26
- common_options.merge(:order => forest_order)
25
+ if forest_order
26
+ has_many :children, -> { order(forest_order) }, common_options
27
27
  else
28
- common_options
28
+ has_many :children, common_options
29
29
  end
30
30
 
31
- has_many :children, children_options
32
-
33
- scope :root, where(forest_foreign_key => nil)
31
+ scope :root, -> { where(forest_foreign_key => nil) }
34
32
 
35
33
  include Edge::Forest::InstanceMethods
36
34
  extend Edge::Forest::ClassMethods
@@ -95,18 +93,18 @@ module Edge
95
93
  #
96
94
  # Only where scopes can precede this in a scope chain
97
95
  def with_descendants
98
- manager = recursive_manager.project('id')
99
- unscoped.where(id: manager)
96
+ manager = recursive_manager.project(arel_table[:id])
97
+ unscoped.where("id in (#{manager.to_sql})")
100
98
  end
101
99
 
102
100
  private
103
101
  def recursive_manager
104
102
  all_nodes = Arel::Table.new(:all_nodes)
105
103
 
106
- original_term = (current_scope || scoped).arel
104
+ original_term = (current_scope || all).select(primary_key, forest_foreign_key).arel
107
105
  iterated_term = Arel::SelectManager.new Arel::Table.engine
108
106
  iterated_term.from(arel_table)
109
- .project(arel_table.columns)
107
+ .project([arel_table[primary_key.to_sym], arel_table[forest_foreign_key.to_sym]])
110
108
  .join(all_nodes)
111
109
  .on(arel_table[forest_foreign_key].eq all_nodes[:id])
112
110
 
@@ -114,8 +112,11 @@ module Edge
114
112
 
115
113
  as_statement = Arel::Nodes::As.new all_nodes, union
116
114
 
117
- manager = Arel::SelectManager.new Arel::Table.engine
118
- manager.with(:recursive, as_statement).from(all_nodes)
115
+ manager = Arel::SelectManager.new(Arel::Table.engine)
116
+ .with(:recursive, as_statement)
117
+ .from(all_nodes)
118
+ .join(arel_table)
119
+ .on(all_nodes[:id].eq(arel_table[:id]))
119
120
  end
120
121
  end
121
122
 
@@ -1,3 +1,3 @@
1
1
  module Edge
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -3,5 +3,6 @@ DROP TABLE IF EXISTS locations;
3
3
  CREATE TABLE locations(
4
4
  id serial PRIMARY KEY,
5
5
  parent_id integer REFERENCES locations,
6
- name varchar NOT NULL
6
+ name varchar NOT NULL,
7
+ attrs json DEFAULT NULL -- include a column that does not have an operator defined that can be used with union
7
8
  );
@@ -4,6 +4,8 @@ class Location < ActiveRecord::Base
4
4
  acts_as_forest :order => "name"
5
5
  end
6
6
 
7
+ Location.delete_all
8
+
7
9
  describe "Edge::Forest" do
8
10
  let!(:usa) { Location.create! :name => "USA" }
9
11
  let!(:illinois) { Location.create! :parent => usa, :name => "Illinois" }
@@ -131,7 +133,7 @@ describe "Edge::Forest" do
131
133
 
132
134
  describe "root scope" do
133
135
  it "returns only root nodes" do
134
- Location.root.all.should include(usa, canada)
136
+ Location.root.should include(usa, canada)
135
137
  end
136
138
  end
137
139
 
@@ -139,13 +141,11 @@ describe "Edge::Forest" do
139
141
  it "preloads all parents and children" do
140
142
  forest = Location.find_forest
141
143
 
142
- Location.with_scope(
143
- :find => Location.where("purposely fail if any Location find happens here")
144
- ) do
144
+ Location.where("purposely fail if any Location find happens here").scoping do
145
145
  forest.each do |tree|
146
146
  tree.descendants.each do |node|
147
147
  node.parent.should be
148
- node.children.should be_kind_of(Array)
148
+ node.children.should be_kind_of(ActiveRecord::Associations::CollectionProxy)
149
149
  end
150
150
  end
151
151
  end
@@ -198,17 +198,17 @@ describe "Edge::Forest" do
198
198
  describe "with_descendants" do
199
199
  context "unscoped" do
200
200
  it "returns all records" do
201
- Location.with_descendants.all.should =~ Location.all
201
+ Location.with_descendants.to_a.should =~ Location.all
202
202
  end
203
203
  end
204
204
 
205
205
  context "scoped" do
206
206
  it "returns a new scope that includes previously scoped records and their descendants" do
207
- Location.where(id: canada.id).with_descendants.all.should =~ [canada, british_columbia]
207
+ Location.where(id: canada.id).with_descendants.to_a.should =~ [canada, british_columbia]
208
208
  end
209
209
 
210
210
  it "is not commutative" do
211
- Location.with_descendants.where(id: canada.id).all.should == [canada]
211
+ Location.with_descendants.where(id: canada.id).to_a.should == [canada]
212
212
  end
213
213
  end
214
214
  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.2.1
4
+ version: 0.3.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: 2013-03-06 00:00:00.000000000 Z
11
+ date: 2013-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
140
  version: '0'
127
141
  requirements: []
128
142
  rubyforge_project:
129
- rubygems_version: 2.0.0
143
+ rubygems_version: 2.0.3
130
144
  signing_key:
131
145
  specification_version: 4
132
146
  summary: Graph functionality for ActiveRecord. Provides tree/forest modeling structure
@@ -136,3 +150,4 @@ test_files:
136
150
  - spec/database_structure.sql
137
151
  - spec/forest_spec.rb
138
152
  - spec/spec_helper.rb
153
+ has_rdoc: