parentry 1.0.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ruby.yml +72 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +38 -0
- data/.tool-versions +1 -0
- data/Appraisals +14 -2
- data/README.md +19 -3
- data/Rakefile +1 -1
- data/gemfiles/{activerecord_5.1.gemfile → activerecord_5.1.5.gemfile} +2 -2
- data/gemfiles/activerecord_5.1.5.gemfile.lock +143 -0
- data/gemfiles/activerecord_5.2.0.gemfile +8 -0
- data/gemfiles/activerecord_5.2.0.gemfile.lock +143 -0
- data/gemfiles/activerecord_6.0.0.gemfile +8 -0
- data/gemfiles/activerecord_6.0.0.gemfile.lock +143 -0
- data/gemfiles/activerecord_6.1.0.gemfile +8 -0
- data/gemfiles/activerecord_6.1.0.gemfile.lock +147 -0
- data/lib/parentry.rb +42 -43
- data/lib/parentry/class_methods.rb +4 -2
- data/lib/parentry/instance_methods.rb +1 -0
- data/lib/parentry/navigation.rb +4 -3
- data/lib/parentry/strategy/array/class_methods.rb +1 -1
- data/lib/parentry/strategy/array/instance_methods.rb +1 -0
- data/lib/parentry/strategy/ltree/class_methods.rb +1 -1
- data/lib/parentry/strategy/ltree/instance_methods.rb +1 -1
- data/lib/parentry/version.rb +1 -1
- data/parentry.gemspec +12 -11
- metadata +85 -44
- data/.travis.yml +0 -11
- data/gemfiles/activerecord_5.1.gemfile.lock +0 -116
@@ -0,0 +1,143 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
parentry (1.3.0)
|
5
|
+
activerecord (>= 5.1, < 6.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (6.0.0)
|
11
|
+
actionview (= 6.0.0)
|
12
|
+
activesupport (= 6.0.0)
|
13
|
+
rack (~> 2.0)
|
14
|
+
rack-test (>= 0.6.3)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
+
actionview (6.0.0)
|
18
|
+
activesupport (= 6.0.0)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubi (~> 1.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
+
activemodel (6.0.0)
|
24
|
+
activesupport (= 6.0.0)
|
25
|
+
activerecord (6.0.0)
|
26
|
+
activemodel (= 6.0.0)
|
27
|
+
activesupport (= 6.0.0)
|
28
|
+
activesupport (6.0.0)
|
29
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
30
|
+
i18n (>= 0.7, < 2)
|
31
|
+
minitest (~> 5.1)
|
32
|
+
tzinfo (~> 1.1)
|
33
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
34
|
+
appraisal (2.2.0)
|
35
|
+
bundler
|
36
|
+
rake
|
37
|
+
thor (>= 0.14.0)
|
38
|
+
ast (2.4.0)
|
39
|
+
builder (3.2.3)
|
40
|
+
coderay (1.1.2)
|
41
|
+
combustion (1.1.1)
|
42
|
+
activesupport (>= 3.0.0)
|
43
|
+
railties (>= 3.0.0)
|
44
|
+
thor (>= 0.14.6)
|
45
|
+
concurrent-ruby (1.1.5)
|
46
|
+
crass (1.0.4)
|
47
|
+
database_cleaner (1.7.0)
|
48
|
+
diff-lcs (1.3)
|
49
|
+
docile (1.3.2)
|
50
|
+
erubi (1.8.0)
|
51
|
+
i18n (1.6.0)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
jaro_winkler (1.5.4)
|
54
|
+
json (2.3.1)
|
55
|
+
loofah (2.2.3)
|
56
|
+
crass (~> 1.0.2)
|
57
|
+
nokogiri (>= 1.5.9)
|
58
|
+
method_source (0.9.2)
|
59
|
+
mini_portile2 (2.4.0)
|
60
|
+
minitest (5.11.3)
|
61
|
+
nokogiri (1.10.7)
|
62
|
+
mini_portile2 (~> 2.4.0)
|
63
|
+
parallel (1.19.1)
|
64
|
+
parser (2.7.0.2)
|
65
|
+
ast (~> 2.4.0)
|
66
|
+
pg (1.2.2)
|
67
|
+
pry (0.12.2)
|
68
|
+
coderay (~> 1.1.0)
|
69
|
+
method_source (~> 0.9.0)
|
70
|
+
rack (2.0.7)
|
71
|
+
rack-test (1.1.0)
|
72
|
+
rack (>= 1.0, < 3)
|
73
|
+
rails-dom-testing (2.0.3)
|
74
|
+
activesupport (>= 4.2.0)
|
75
|
+
nokogiri (>= 1.6)
|
76
|
+
rails-html-sanitizer (1.2.0)
|
77
|
+
loofah (~> 2.2, >= 2.2.2)
|
78
|
+
railties (6.0.0)
|
79
|
+
actionpack (= 6.0.0)
|
80
|
+
activesupport (= 6.0.0)
|
81
|
+
method_source
|
82
|
+
rake (>= 0.8.7)
|
83
|
+
thor (>= 0.20.3, < 2.0)
|
84
|
+
rainbow (3.0.0)
|
85
|
+
rake (12.3.3)
|
86
|
+
rspec-core (3.8.2)
|
87
|
+
rspec-support (~> 3.8.0)
|
88
|
+
rspec-expectations (3.8.4)
|
89
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
90
|
+
rspec-support (~> 3.8.0)
|
91
|
+
rspec-mocks (3.8.1)
|
92
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
93
|
+
rspec-support (~> 3.8.0)
|
94
|
+
rspec-rails (3.8.2)
|
95
|
+
actionpack (>= 3.0)
|
96
|
+
activesupport (>= 3.0)
|
97
|
+
railties (>= 3.0)
|
98
|
+
rspec-core (~> 3.8.0)
|
99
|
+
rspec-expectations (~> 3.8.0)
|
100
|
+
rspec-mocks (~> 3.8.0)
|
101
|
+
rspec-support (~> 3.8.0)
|
102
|
+
rspec-support (3.8.2)
|
103
|
+
rubocop (0.79.0)
|
104
|
+
jaro_winkler (~> 1.5.1)
|
105
|
+
parallel (~> 1.10)
|
106
|
+
parser (>= 2.7.0.1)
|
107
|
+
rainbow (>= 2.2.2, < 4.0)
|
108
|
+
ruby-progressbar (~> 1.7)
|
109
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
110
|
+
rubocop-rspec (1.37.1)
|
111
|
+
rubocop (>= 0.68.1)
|
112
|
+
ruby-progressbar (1.10.1)
|
113
|
+
simplecov (0.17.0)
|
114
|
+
docile (~> 1.1)
|
115
|
+
json (>= 1.8, < 3)
|
116
|
+
simplecov-html (~> 0.10.0)
|
117
|
+
simplecov-html (0.10.2)
|
118
|
+
thor (0.20.3)
|
119
|
+
thread_safe (0.3.6)
|
120
|
+
tzinfo (1.2.8)
|
121
|
+
thread_safe (~> 0.1)
|
122
|
+
unicode-display_width (1.6.1)
|
123
|
+
zeitwerk (2.1.9)
|
124
|
+
|
125
|
+
PLATFORMS
|
126
|
+
ruby
|
127
|
+
|
128
|
+
DEPENDENCIES
|
129
|
+
activerecord (= 6.0.0)
|
130
|
+
appraisal
|
131
|
+
bundler (~> 2.1)
|
132
|
+
combustion (~> 1.1)
|
133
|
+
database_cleaner (~> 1.6)
|
134
|
+
parentry!
|
135
|
+
pg (~> 1.2)
|
136
|
+
pry (~> 0.10)
|
137
|
+
rake (~> 12.3)
|
138
|
+
rspec-rails (~> 3.7)
|
139
|
+
rubocop-rspec (~> 1.37)
|
140
|
+
simplecov (~> 0.16)
|
141
|
+
|
142
|
+
BUNDLED WITH
|
143
|
+
2.1.4
|
@@ -0,0 +1,147 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
parentry (1.3.0)
|
5
|
+
activerecord (>= 5.1, < 6.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actionpack (6.0.0)
|
11
|
+
actionview (= 6.0.0)
|
12
|
+
activesupport (= 6.0.0)
|
13
|
+
rack (~> 2.0)
|
14
|
+
rack-test (>= 0.6.3)
|
15
|
+
rails-dom-testing (~> 2.0)
|
16
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
17
|
+
actionview (6.0.0)
|
18
|
+
activesupport (= 6.0.0)
|
19
|
+
builder (~> 3.1)
|
20
|
+
erubi (~> 1.4)
|
21
|
+
rails-dom-testing (~> 2.0)
|
22
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
23
|
+
activemodel (6.0.0)
|
24
|
+
activesupport (= 6.0.0)
|
25
|
+
activerecord (6.0.0)
|
26
|
+
activemodel (= 6.0.0)
|
27
|
+
activesupport (= 6.0.0)
|
28
|
+
activesupport (6.0.0)
|
29
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
30
|
+
i18n (>= 0.7, < 2)
|
31
|
+
minitest (~> 5.1)
|
32
|
+
tzinfo (~> 1.1)
|
33
|
+
zeitwerk (~> 2.1, >= 2.1.8)
|
34
|
+
appraisal (2.3.0)
|
35
|
+
bundler
|
36
|
+
rake
|
37
|
+
thor (>= 0.14.0)
|
38
|
+
ast (2.4.1)
|
39
|
+
builder (3.2.4)
|
40
|
+
coderay (1.1.3)
|
41
|
+
combustion (1.3.1)
|
42
|
+
activesupport (>= 3.0.0)
|
43
|
+
railties (>= 3.0.0)
|
44
|
+
thor (>= 0.14.6)
|
45
|
+
concurrent-ruby (1.1.7)
|
46
|
+
crass (1.0.6)
|
47
|
+
database_cleaner (1.8.5)
|
48
|
+
diff-lcs (1.4.4)
|
49
|
+
docile (1.3.2)
|
50
|
+
erubi (1.10.0)
|
51
|
+
i18n (1.8.5)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
loofah (2.7.0)
|
54
|
+
crass (~> 1.0.2)
|
55
|
+
nokogiri (>= 1.5.9)
|
56
|
+
method_source (1.0.0)
|
57
|
+
mini_portile2 (2.4.0)
|
58
|
+
minitest (5.14.2)
|
59
|
+
nokogiri (1.10.10)
|
60
|
+
mini_portile2 (~> 2.4.0)
|
61
|
+
parallel (1.20.0)
|
62
|
+
parser (2.7.2.0)
|
63
|
+
ast (~> 2.4.1)
|
64
|
+
pg (1.2.3)
|
65
|
+
pry (0.13.1)
|
66
|
+
coderay (~> 1.1)
|
67
|
+
method_source (~> 1.0)
|
68
|
+
rack (2.2.3)
|
69
|
+
rack-test (1.1.0)
|
70
|
+
rack (>= 1.0, < 3)
|
71
|
+
rails-dom-testing (2.0.3)
|
72
|
+
activesupport (>= 4.2.0)
|
73
|
+
nokogiri (>= 1.6)
|
74
|
+
rails-html-sanitizer (1.3.0)
|
75
|
+
loofah (~> 2.3)
|
76
|
+
railties (6.0.0)
|
77
|
+
actionpack (= 6.0.0)
|
78
|
+
activesupport (= 6.0.0)
|
79
|
+
method_source
|
80
|
+
rake (>= 0.8.7)
|
81
|
+
thor (>= 0.20.3, < 2.0)
|
82
|
+
rainbow (3.0.0)
|
83
|
+
rake (12.3.3)
|
84
|
+
regexp_parser (1.8.2)
|
85
|
+
rexml (3.2.4)
|
86
|
+
rspec-core (3.9.3)
|
87
|
+
rspec-support (~> 3.9.3)
|
88
|
+
rspec-expectations (3.9.3)
|
89
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
90
|
+
rspec-support (~> 3.9.0)
|
91
|
+
rspec-mocks (3.9.1)
|
92
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
93
|
+
rspec-support (~> 3.9.0)
|
94
|
+
rspec-rails (3.9.1)
|
95
|
+
actionpack (>= 3.0)
|
96
|
+
activesupport (>= 3.0)
|
97
|
+
railties (>= 3.0)
|
98
|
+
rspec-core (~> 3.9.0)
|
99
|
+
rspec-expectations (~> 3.9.0)
|
100
|
+
rspec-mocks (~> 3.9.0)
|
101
|
+
rspec-support (~> 3.9.0)
|
102
|
+
rspec-support (3.9.4)
|
103
|
+
rubocop (0.93.1)
|
104
|
+
parallel (~> 1.10)
|
105
|
+
parser (>= 2.7.1.5)
|
106
|
+
rainbow (>= 2.2.2, < 4.0)
|
107
|
+
regexp_parser (>= 1.8)
|
108
|
+
rexml
|
109
|
+
rubocop-ast (>= 0.6.0)
|
110
|
+
ruby-progressbar (~> 1.7)
|
111
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
112
|
+
rubocop-ast (1.1.1)
|
113
|
+
parser (>= 2.7.1.5)
|
114
|
+
rubocop-rspec (1.44.1)
|
115
|
+
rubocop (~> 0.87)
|
116
|
+
rubocop-ast (>= 0.7.1)
|
117
|
+
ruby-progressbar (1.10.1)
|
118
|
+
simplecov (0.19.1)
|
119
|
+
docile (~> 1.1)
|
120
|
+
simplecov-html (~> 0.11)
|
121
|
+
simplecov-html (0.12.3)
|
122
|
+
thor (1.0.1)
|
123
|
+
thread_safe (0.3.6)
|
124
|
+
tzinfo (1.2.8)
|
125
|
+
thread_safe (~> 0.1)
|
126
|
+
unicode-display_width (1.7.0)
|
127
|
+
zeitwerk (2.4.2)
|
128
|
+
|
129
|
+
PLATFORMS
|
130
|
+
ruby
|
131
|
+
|
132
|
+
DEPENDENCIES
|
133
|
+
activerecord (= 6.0.0)
|
134
|
+
appraisal
|
135
|
+
bundler (~> 2.1)
|
136
|
+
combustion (~> 1.1)
|
137
|
+
database_cleaner (~> 1.6)
|
138
|
+
parentry!
|
139
|
+
pg (~> 1.2)
|
140
|
+
pry (~> 0.10)
|
141
|
+
rake (~> 12.3)
|
142
|
+
rspec-rails (~> 3.7)
|
143
|
+
rubocop-rspec (~> 1.37)
|
144
|
+
simplecov (~> 0.16)
|
145
|
+
|
146
|
+
BUNDLED WITH
|
147
|
+
2.1.4
|
data/lib/parentry.rb
CHANGED
@@ -6,50 +6,49 @@ module Parentry
|
|
6
6
|
autoload :Navigation, 'parentry/navigation'
|
7
7
|
autoload :ClassMethods, 'parentry/class_methods'
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
after_create :commit_parentry
|
25
|
-
before_update :assign_parentry, if: proc { changes[:parent_id].present? }
|
26
|
-
after_update :cascade_parentry, if: proc { saved_changes[parentry_column].present? }
|
27
|
-
|
28
|
-
before_validation :cache_parentry_depth, if: proc { cache_depth }
|
29
|
-
before_save :cache_parentry_depth, if: proc { cache_depth }
|
30
|
-
|
31
|
-
after_save :touch_ancestors_callback
|
32
|
-
after_touch :touch_ancestors_callback
|
33
|
-
after_destroy :touch_ancestors_callback
|
34
|
-
|
35
|
-
scope :order_by_parentry, -> { order(parentry_depth_function) }
|
36
|
-
|
37
|
-
scope :before_depth, ->(depth) { where("#{parentry_depth_function} - 1 < ?", depth + depth_offset) }
|
38
|
-
scope :to_depth, ->(depth) { where("#{parentry_depth_function} - 1 <= ?", depth + depth_offset) }
|
39
|
-
scope :at_depth, ->(depth) { where("#{parentry_depth_function} - 1 = ?", depth + depth_offset) }
|
40
|
-
scope :from_depth, ->(depth) { where("#{parentry_depth_function} - 1 >= ?", depth + depth_offset) }
|
41
|
-
scope :after_depth, ->(depth) { where("#{parentry_depth_function} - 1 > ?", depth + depth_offset) }
|
42
|
-
|
43
|
-
scope :roots, -> { where("#{parentry_depth_function} = 1") }
|
44
|
-
scope :ancestors_of, ->(node) { where(node.ancestor_conditions).where.not(id: node.id) }
|
45
|
-
scope :children_of, ->(node) { where(parent_id: node.id) }
|
46
|
-
scope :descendants_of, ->(node) { subtree_of(node).where.not(id: node.id) }
|
47
|
-
scope :subtree_of, ->(node) { where(node.subtree_conditions) }
|
48
|
-
scope :siblings_of, ->(node) { where(parent_id: node.parent_id).where.not(id: node.id) }
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
# rubocop:disable Metrics/BlockLength
|
12
|
+
included do
|
13
|
+
include Navigation
|
14
|
+
include InstanceMethods
|
15
|
+
|
16
|
+
mattr_accessor :parentry_strategy, :parentry_column, :depth_offset, :cache_depth, :touch_ancestors
|
17
|
+
|
18
|
+
belongs_to :parent, class_name: base_class.name, optional: true
|
19
|
+
has_many :children, class_name: base_class.name, foreign_key: :parent_id, dependent: :destroy
|
20
|
+
|
21
|
+
validate do
|
22
|
+
errors.add(:parent, 'must be persisted') unless parent.blank? || parent.persisted?
|
49
23
|
end
|
50
24
|
|
51
|
-
|
52
|
-
|
53
|
-
|
25
|
+
validate :prevent_circular_parentry
|
26
|
+
|
27
|
+
after_create :commit_parentry
|
28
|
+
before_update :assign_parentry, if: proc { changes[:parent_id].present? }
|
29
|
+
after_update :cascade_parentry, if: proc { saved_changes[parentry_column].present? }
|
30
|
+
|
31
|
+
before_validation :cache_parentry_depth, if: proc { cache_depth }
|
32
|
+
before_save :cache_parentry_depth, if: proc { cache_depth }
|
33
|
+
|
34
|
+
after_save :touch_ancestors_callback
|
35
|
+
after_touch :touch_ancestors_callback
|
36
|
+
after_destroy :touch_ancestors_callback
|
37
|
+
|
38
|
+
scope :order_by_parentry, -> { order(parentry_depth_function) }
|
39
|
+
|
40
|
+
scope :before_depth, ->(depth) { where("#{parentry_depth_function} - 1 < ?", depth + depth_offset) }
|
41
|
+
scope :to_depth, ->(depth) { where("#{parentry_depth_function} - 1 <= ?", depth + depth_offset) }
|
42
|
+
scope :at_depth, ->(depth) { where("#{parentry_depth_function} - 1 = ?", depth + depth_offset) }
|
43
|
+
scope :from_depth, ->(depth) { where("#{parentry_depth_function} - 1 >= ?", depth + depth_offset) }
|
44
|
+
scope :after_depth, ->(depth) { where("#{parentry_depth_function} - 1 > ?", depth + depth_offset) }
|
45
|
+
|
46
|
+
scope :roots, -> { where("#{parentry_depth_function} = 1") }
|
47
|
+
scope :ancestors_of, ->(node) { where(node.ancestor_conditions).where.not(id: node.id) }
|
48
|
+
scope :children_of, ->(node) { where(parent_id: node.id) }
|
49
|
+
scope :descendants_of, ->(node) { subtree_of(node).where.not(id: node.id) }
|
50
|
+
scope :subtree_of, ->(node) { where(node.subtree_conditions) }
|
51
|
+
scope :siblings_of, ->(node) { where(parent_id: node.parent_id).where.not(id: node.id) }
|
54
52
|
end
|
53
|
+
# rubocop:enable Metrics/BlockLength
|
55
54
|
end
|
@@ -11,12 +11,13 @@ module Parentry
|
|
11
11
|
include Strategy::Array if parentry_strategy == 'array'
|
12
12
|
end
|
13
13
|
|
14
|
+
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
14
15
|
def arrange(options = {})
|
15
16
|
scope =
|
16
17
|
if (order = options.delete(:order))
|
17
|
-
|
18
|
+
base_class.order_by_parentry.order(order)
|
18
19
|
else
|
19
|
-
|
20
|
+
base_class.order_by_parentry
|
20
21
|
end
|
21
22
|
|
22
23
|
scope.where(options).each_with_object(Hash.new { |h, k| h[k] = {} }) do |node, memo|
|
@@ -27,5 +28,6 @@ module Parentry
|
|
27
28
|
insert_node[node] = {}
|
28
29
|
end
|
29
30
|
end
|
31
|
+
# rubocop:enable Metrics/AbcSize,Metrics/MethodLength
|
30
32
|
end
|
31
33
|
end
|
data/lib/parentry/navigation.rb
CHANGED
@@ -33,9 +33,9 @@ module Parentry
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def leaf?
|
36
|
-
children.size
|
36
|
+
children.size.zero?
|
37
37
|
end
|
38
|
-
|
38
|
+
alias childless? leaf?
|
39
39
|
|
40
40
|
def children?
|
41
41
|
!leaf?
|
@@ -50,7 +50,7 @@ module Parentry
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def siblings?
|
53
|
-
siblings.size
|
53
|
+
siblings.size.positive?
|
54
54
|
end
|
55
55
|
|
56
56
|
def only_child?
|
@@ -80,6 +80,7 @@ module Parentry
|
|
80
80
|
def depth
|
81
81
|
return depth_offset if root?
|
82
82
|
return parent.depth + 1 if changes[:parent_id].present?
|
83
|
+
|
83
84
|
path_ids.size - 1 + depth_offset
|
84
85
|
end
|
85
86
|
|