acts_as_recursive_tree 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/acts_as_recursive_tree/builders/ancestors.rb +1 -4
- data/lib/acts_as_recursive_tree/builders/descendants.rb +1 -3
- data/lib/acts_as_recursive_tree/builders/relation_builder.rb +11 -18
- data/lib/acts_as_recursive_tree/builders/strategy.rb +4 -1
- data/lib/acts_as_recursive_tree/builders/strategy/ancestor.rb +17 -0
- data/lib/acts_as_recursive_tree/builders/strategy/descendant.rb +17 -0
- data/lib/acts_as_recursive_tree/builders/strategy/join.rb +6 -2
- data/lib/acts_as_recursive_tree/options/query_options.rb +8 -1
- data/lib/acts_as_recursive_tree/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa1a901a4881db96a5aff4515cb0fe5f5b52d8713c7277aa67b4c5e3ffba70d4
|
4
|
+
data.tar.gz: 5201f9c51c39a944b2fcb7e8abafe24d07722870f2545cf0cfb1116a46567238
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '028d295a1d44a545798862a602448f635dd854bc63373d654ebaa217b41d8fded8327d6c10d0d64a566d7fd96beef3430261f66a135bdb1d7484cbcd25d3cae7'
|
7
|
+
data.tar.gz: 0a0746c45165e981ef5965bb751d5bfc88ac8ffdb07edc898799b4fa781a2f302d12c57b4ee2582e41c8b5c439d9c50b0019aa60f0b21a270f8388911dcc1939
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
### Version 2.1.1
|
2
|
+
- Enabled subselect query when using depth
|
3
|
+
- new QueryOption query_strategy for forcing a specific strategy (:join, :subselect)
|
4
|
+
|
1
5
|
### Version 2.1.0
|
2
6
|
- BUGFIX association self_and_siblings not working
|
3
7
|
- BUGFIX primary_key of model is retrieved on first usage and not on setup
|
@@ -1,10 +1,7 @@
|
|
1
1
|
module ActsAsRecursiveTree
|
2
2
|
module Builders
|
3
3
|
class Ancestors < RelationBuilder
|
4
|
-
|
5
|
-
def build_join_condition
|
6
|
-
travers_loc_table[parent_key].eq(base_table[primary_key])
|
7
|
-
end
|
4
|
+
self.traversal_strategy = ActsAsRecursiveTree::Builders::Strategy::Ancestor
|
8
5
|
|
9
6
|
def get_query_options(_)
|
10
7
|
opts = super
|
@@ -1,9 +1,7 @@
|
|
1
1
|
module ActsAsRecursiveTree
|
2
2
|
module Builders
|
3
3
|
class Descendants < RelationBuilder
|
4
|
-
|
5
|
-
base_table[parent_key].eq(travers_loc_table[primary_key])
|
6
|
-
end
|
4
|
+
self.traversal_strategy = ActsAsRecursiveTree::Builders::Strategy::Descendant
|
7
5
|
end
|
8
6
|
end
|
9
7
|
end
|
@@ -9,6 +9,8 @@ module ActsAsRecursiveTree
|
|
9
9
|
new(klass, ids, exclude_ids: exclude_ids, &block).build
|
10
10
|
end
|
11
11
|
|
12
|
+
class_attribute :traversal_strategy, instance_writer: false
|
13
|
+
|
12
14
|
attr_reader :klass, :ids, :recursive_temp_table, :travers_loc_table, :without_ids
|
13
15
|
mattr_reader(:random) { Random.new }
|
14
16
|
|
@@ -60,15 +62,10 @@ module ActsAsRecursiveTree
|
|
60
62
|
relation.where(ids.apply_negated_to(base_table[primary_key]))
|
61
63
|
end
|
62
64
|
|
63
|
-
def apply_depth(
|
64
|
-
return
|
65
|
-
|
66
|
-
relation.where(depth.apply_to(recursive_temp_table[depth_column]))
|
67
|
-
end
|
65
|
+
def apply_depth(select_manager)
|
66
|
+
return select_manager unless depth_present?
|
68
67
|
|
69
|
-
|
70
|
-
return relation unless ensure_ordering
|
71
|
-
relation.order(recursive_temp_table[depth_column].asc)
|
68
|
+
select_manager.where(depth.apply_to(travers_loc_table[depth_column]))
|
72
69
|
end
|
73
70
|
|
74
71
|
def create_select_manger(column = nil)
|
@@ -78,7 +75,9 @@ module ActsAsRecursiveTree
|
|
78
75
|
Arel.star
|
79
76
|
end
|
80
77
|
|
81
|
-
travers_loc_table.project(projections).with(:recursive, build_cte_table)
|
78
|
+
select_mgr = travers_loc_table.project(projections).with(:recursive, build_cte_table)
|
79
|
+
|
80
|
+
apply_depth(select_mgr)
|
82
81
|
end
|
83
82
|
|
84
83
|
def build_cte_table
|
@@ -101,7 +100,9 @@ module ActsAsRecursiveTree
|
|
101
100
|
end
|
102
101
|
|
103
102
|
def build_union_select
|
104
|
-
join_condition = apply_parent_type_column(
|
103
|
+
join_condition = apply_parent_type_column(
|
104
|
+
traversal_strategy.build(self)
|
105
|
+
)
|
105
106
|
|
106
107
|
select_manager = base_table.join(travers_loc_table).on(join_condition)
|
107
108
|
|
@@ -132,14 +133,6 @@ module ActsAsRecursiveTree
|
|
132
133
|
return relation if condition.nil?
|
133
134
|
relation.merge(condition)
|
134
135
|
end
|
135
|
-
|
136
|
-
#
|
137
|
-
# U
|
138
|
-
#
|
139
|
-
def build_join_condition
|
140
|
-
raise 'not implemented'
|
141
|
-
end
|
142
|
-
|
143
136
|
end
|
144
137
|
end
|
145
138
|
end
|
@@ -9,6 +9,9 @@ module ActsAsRecursiveTree
|
|
9
9
|
autoload :Join
|
10
10
|
autoload :Subselect
|
11
11
|
|
12
|
+
autoload :Descendant
|
13
|
+
autoload :Ancestor
|
14
|
+
|
12
15
|
#
|
13
16
|
# Returns a Strategy appropriate for query_opts
|
14
17
|
#
|
@@ -16,7 +19,7 @@ module ActsAsRecursiveTree
|
|
16
19
|
#
|
17
20
|
# @return a strategy class best suited for the opts
|
18
21
|
def self.for_query_options(query_opts)
|
19
|
-
if query_opts.
|
22
|
+
if query_opts.ensure_ordering || query_opts.query_strategy == :join
|
20
23
|
Join
|
21
24
|
else
|
22
25
|
Subselect
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ActsAsRecursiveTree
|
2
|
+
module Builders
|
3
|
+
module Strategy
|
4
|
+
#
|
5
|
+
# Strategy for building ancestors relation
|
6
|
+
#
|
7
|
+
module Ancestor
|
8
|
+
#
|
9
|
+
# Builds the relation
|
10
|
+
#
|
11
|
+
def self.build(builder)
|
12
|
+
builder.travers_loc_table[builder.parent_key].eq(builder.base_table[builder.primary_key])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ActsAsRecursiveTree
|
2
|
+
module Builders
|
3
|
+
module Strategy
|
4
|
+
#
|
5
|
+
# Strategy for building descendants relation
|
6
|
+
#
|
7
|
+
module Descendant
|
8
|
+
#
|
9
|
+
# Builds the relation
|
10
|
+
#
|
11
|
+
def self.build(builder)
|
12
|
+
builder.base_table[builder.parent_key].eq(builder.travers_loc_table[builder.primary_key])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -19,10 +19,14 @@ module ActsAsRecursiveTree
|
|
19
19
|
|
20
20
|
relation = builder.klass.joins(final_select_mgr.join_sources)
|
21
21
|
|
22
|
-
relation = builder
|
23
|
-
relation = builder.apply_order(relation)
|
22
|
+
relation = apply_order(builder, relation)
|
24
23
|
relation
|
25
24
|
end
|
25
|
+
|
26
|
+
def self.apply_order(builder, relation)
|
27
|
+
return relation unless builder.ensure_ordering
|
28
|
+
relation.order(builder.recursive_temp_table[builder.depth_column].asc)
|
29
|
+
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
end
|
@@ -2,8 +2,10 @@ module ActsAsRecursiveTree
|
|
2
2
|
module Options
|
3
3
|
class QueryOptions
|
4
4
|
|
5
|
+
STRATEGIES = %i[subselect, join].freeze
|
6
|
+
|
5
7
|
attr_accessor :condition
|
6
|
-
attr_reader :ensure_ordering
|
8
|
+
attr_reader :ensure_ordering, :query_strategy
|
7
9
|
|
8
10
|
def depth
|
9
11
|
@depth ||= DepthCondition.new
|
@@ -16,6 +18,11 @@ module ActsAsRecursiveTree
|
|
16
18
|
def depth_present?
|
17
19
|
@depth.present?
|
18
20
|
end
|
21
|
+
|
22
|
+
def query_strategy=(strategy)
|
23
|
+
raise "invalid strategy #{strategy} - only #{STRATEGIES} are allowed" unless STRATEGIES.include?(strategy)
|
24
|
+
@query_strategy = strategy
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_recursive_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wolfgang Wedelich-John
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -128,6 +128,8 @@ files:
|
|
128
128
|
- lib/acts_as_recursive_tree/builders/leaves.rb
|
129
129
|
- lib/acts_as_recursive_tree/builders/relation_builder.rb
|
130
130
|
- lib/acts_as_recursive_tree/builders/strategy.rb
|
131
|
+
- lib/acts_as_recursive_tree/builders/strategy/ancestor.rb
|
132
|
+
- lib/acts_as_recursive_tree/builders/strategy/descendant.rb
|
131
133
|
- lib/acts_as_recursive_tree/builders/strategy/join.rb
|
132
134
|
- lib/acts_as_recursive_tree/builders/strategy/subselect.rb
|
133
135
|
- lib/acts_as_recursive_tree/config.rb
|