relation 0.3.8 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +10 -8
- data/.gitignore +1 -1
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/Gemfile +7 -5
- data/Gemfile.lock +141 -115
- data/MIT-LICENSE +3 -1
- data/README.md +36 -26
- data/Rakefile +5 -5
- data/app/models/dangling.rb +7 -6
- data/app/models/relation.rb +4 -2
- data/app/models/relation_ext.rb +6 -4
- data/db/migrate/{20150810152808_relation.rb → 003_create_relations.rb} +2 -2
- data/lib/relation/engine.rb +1 -23
- data/lib/relation/version.rb +13 -9
- data/lib/relation.rb +3 -6
- data/relation.gemspec +18 -25
- data/test/dangling_test.rb +17 -23
- data/test/internal/app/models/order.rb +2 -0
- data/test/internal/app/models/user.rb +2 -0
- data/test/internal/config/database.yml +3 -0
- data/test/internal/db/schema.rb +28 -0
- data/test/relation_ext_test.rb +14 -21
- data/test/relation_test.rb +10 -17
- data/test/test_helper.rb +11 -12
- metadata +15 -58
- data/.rubocop.yml +0 -9
- data/.watchr +0 -59
- data/Appraisals +0 -19
- data/gemfiles/rails_6.0.gemfile +0 -13
- data/gemfiles/rails_6.1.gemfile +0 -13
- data/test/support/database.rb +0 -57
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dafdb00f20ba4c9fbd3e810ec8fd5abbea1c8b20ce27a5f9b0d15de20a82a4a0
|
4
|
+
data.tar.gz: 961c6ca2fd28da3fc86df5232c44fbf794f715abf5fa5a10d4707c7e3ddd3263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82f66c8fa2f5fe8ce4ee7036db43be7d47838cd9861365f84cd8851a062941c6611132f4ec50c6af1286b193d3273ee5633f3d09a431e2ac62306f02ac045105
|
7
|
+
data.tar.gz: 8817aab0b713c3e83e986713a9f43f5701138ffcf478fb2dc24f9083093d3f2039ce9de423b2b9b3ac5bc66dfd75e04dd453e11cafb9e8c9cc664b34cf9a258e
|
data/.github/workflows/rake.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
# see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
|
1
2
|
name: Rake
|
2
3
|
|
3
|
-
#on: [push, pull_request]
|
4
4
|
on: [push]
|
5
5
|
|
6
6
|
jobs:
|
@@ -8,17 +8,19 @@ jobs:
|
|
8
8
|
strategy:
|
9
9
|
fail-fast: false
|
10
10
|
matrix:
|
11
|
-
# os: [ubuntu-latest, macos-latest]
|
12
11
|
os: [ubuntu-latest]
|
13
|
-
|
14
|
-
|
15
|
-
ruby: [2.7]
|
12
|
+
ruby: ["2.7", "3.0", "3.2", head]
|
13
|
+
test_command: ["bundle exec rake"]
|
16
14
|
runs-on: ${{ matrix.os }}
|
17
15
|
|
18
16
|
steps:
|
19
|
-
- uses: actions/checkout@
|
17
|
+
- uses: actions/checkout@v3
|
20
18
|
- uses: ruby/setup-ruby@v1
|
21
19
|
with:
|
22
20
|
ruby-version: ${{ matrix.ruby }}
|
23
|
-
|
24
|
-
|
21
|
+
- name: Bundle install
|
22
|
+
run: |
|
23
|
+
bundle config path /home/runner/bundle
|
24
|
+
bundle install
|
25
|
+
bundle update
|
26
|
+
- run: ${{ matrix.test_command }}
|
data/.gitignore
CHANGED
data/.ruby-gemset
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rails-
|
1
|
+
rails-7.0
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-3.2.2
|
data/Gemfile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
3
|
|
4
|
-
gem
|
4
|
+
gem "rails"
|
5
5
|
|
6
6
|
group :test do
|
7
|
-
gem
|
8
|
-
gem
|
9
|
-
gem
|
7
|
+
gem "minitest-spec-rails"
|
8
|
+
gem "observr"
|
9
|
+
gem "ricecream"
|
10
|
+
gem "simplecov", require: false
|
11
|
+
gem "standard", require: false
|
10
12
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,184 +1,210 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
relation (0.3
|
5
|
-
activerecord
|
4
|
+
relation (0.4.3)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
9
8
|
specs:
|
10
|
-
actioncable (
|
11
|
-
actionpack (=
|
12
|
-
activesupport (=
|
9
|
+
actioncable (7.0.4.3)
|
10
|
+
actionpack (= 7.0.4.3)
|
11
|
+
activesupport (= 7.0.4.3)
|
13
12
|
nio4r (~> 2.0)
|
14
13
|
websocket-driver (>= 0.6.1)
|
15
|
-
actionmailbox (
|
16
|
-
actionpack (=
|
17
|
-
activejob (=
|
18
|
-
activerecord (=
|
19
|
-
activestorage (=
|
20
|
-
activesupport (=
|
14
|
+
actionmailbox (7.0.4.3)
|
15
|
+
actionpack (= 7.0.4.3)
|
16
|
+
activejob (= 7.0.4.3)
|
17
|
+
activerecord (= 7.0.4.3)
|
18
|
+
activestorage (= 7.0.4.3)
|
19
|
+
activesupport (= 7.0.4.3)
|
21
20
|
mail (>= 2.7.1)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
net-imap
|
22
|
+
net-pop
|
23
|
+
net-smtp
|
24
|
+
actionmailer (7.0.4.3)
|
25
|
+
actionpack (= 7.0.4.3)
|
26
|
+
actionview (= 7.0.4.3)
|
27
|
+
activejob (= 7.0.4.3)
|
28
|
+
activesupport (= 7.0.4.3)
|
27
29
|
mail (~> 2.5, >= 2.5.4)
|
30
|
+
net-imap
|
31
|
+
net-pop
|
32
|
+
net-smtp
|
28
33
|
rails-dom-testing (~> 2.0)
|
29
|
-
actionpack (
|
30
|
-
actionview (=
|
31
|
-
activesupport (=
|
32
|
-
rack (~> 2.0, >= 2.0
|
34
|
+
actionpack (7.0.4.3)
|
35
|
+
actionview (= 7.0.4.3)
|
36
|
+
activesupport (= 7.0.4.3)
|
37
|
+
rack (~> 2.0, >= 2.2.0)
|
33
38
|
rack-test (>= 0.6.3)
|
34
39
|
rails-dom-testing (~> 2.0)
|
35
40
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
-
actiontext (
|
37
|
-
actionpack (=
|
38
|
-
activerecord (=
|
39
|
-
activestorage (=
|
40
|
-
activesupport (=
|
41
|
+
actiontext (7.0.4.3)
|
42
|
+
actionpack (= 7.0.4.3)
|
43
|
+
activerecord (= 7.0.4.3)
|
44
|
+
activestorage (= 7.0.4.3)
|
45
|
+
activesupport (= 7.0.4.3)
|
46
|
+
globalid (>= 0.6.0)
|
41
47
|
nokogiri (>= 1.8.5)
|
42
|
-
actionview (
|
43
|
-
activesupport (=
|
48
|
+
actionview (7.0.4.3)
|
49
|
+
activesupport (= 7.0.4.3)
|
44
50
|
builder (~> 3.1)
|
45
51
|
erubi (~> 1.4)
|
46
52
|
rails-dom-testing (~> 2.0)
|
47
53
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
-
activejob (
|
49
|
-
activesupport (=
|
54
|
+
activejob (7.0.4.3)
|
55
|
+
activesupport (= 7.0.4.3)
|
50
56
|
globalid (>= 0.3.6)
|
51
|
-
activemodel (
|
52
|
-
activesupport (=
|
53
|
-
activerecord (
|
54
|
-
activemodel (=
|
55
|
-
activesupport (=
|
56
|
-
activestorage (
|
57
|
-
actionpack (=
|
58
|
-
activejob (=
|
59
|
-
activerecord (=
|
60
|
-
activesupport (=
|
61
|
-
marcel (~> 1.0
|
62
|
-
mini_mime (
|
63
|
-
activesupport (
|
57
|
+
activemodel (7.0.4.3)
|
58
|
+
activesupport (= 7.0.4.3)
|
59
|
+
activerecord (7.0.4.3)
|
60
|
+
activemodel (= 7.0.4.3)
|
61
|
+
activesupport (= 7.0.4.3)
|
62
|
+
activestorage (7.0.4.3)
|
63
|
+
actionpack (= 7.0.4.3)
|
64
|
+
activejob (= 7.0.4.3)
|
65
|
+
activerecord (= 7.0.4.3)
|
66
|
+
activesupport (= 7.0.4.3)
|
67
|
+
marcel (~> 1.0)
|
68
|
+
mini_mime (>= 1.1.0)
|
69
|
+
activesupport (7.0.4.3)
|
64
70
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
65
71
|
i18n (>= 1.6, < 2)
|
66
72
|
minitest (>= 5.1)
|
67
73
|
tzinfo (~> 2.0)
|
68
|
-
zeitwerk (~> 2.3)
|
69
|
-
appraisal (2.4.0)
|
70
|
-
bundler
|
71
|
-
rake
|
72
|
-
thor (>= 0.14.0)
|
73
74
|
ast (2.4.2)
|
74
75
|
builder (3.2.4)
|
75
|
-
|
76
|
+
combustion (1.3.7)
|
77
|
+
activesupport (>= 3.0.0)
|
78
|
+
railties (>= 3.0.0)
|
79
|
+
thor (>= 0.14.6)
|
80
|
+
concurrent-ruby (1.2.2)
|
76
81
|
crass (1.0.6)
|
82
|
+
date (3.3.3)
|
77
83
|
docile (1.4.0)
|
78
|
-
erubi (1.
|
79
|
-
globalid (
|
80
|
-
activesupport (>=
|
81
|
-
i18n (1.
|
84
|
+
erubi (1.12.0)
|
85
|
+
globalid (1.1.0)
|
86
|
+
activesupport (>= 5.0)
|
87
|
+
i18n (1.12.0)
|
82
88
|
concurrent-ruby (~> 1.0)
|
83
|
-
|
89
|
+
json (2.6.3)
|
90
|
+
language_server-protocol (3.17.0.3)
|
91
|
+
loofah (2.20.0)
|
84
92
|
crass (~> 1.0.2)
|
85
93
|
nokogiri (>= 1.5.9)
|
86
|
-
mail (2.
|
94
|
+
mail (2.8.1)
|
87
95
|
mini_mime (>= 0.1.1)
|
88
|
-
|
96
|
+
net-imap
|
97
|
+
net-pop
|
98
|
+
net-smtp
|
99
|
+
marcel (1.0.2)
|
89
100
|
method_source (1.0.0)
|
90
|
-
mini_mime (1.
|
91
|
-
minitest (5.
|
92
|
-
|
93
|
-
|
101
|
+
mini_mime (1.1.2)
|
102
|
+
minitest (5.18.0)
|
103
|
+
minitest-spec-rails (6.2.0)
|
104
|
+
minitest (>= 5.0)
|
105
|
+
railties (>= 4.1)
|
106
|
+
net-imap (0.3.4)
|
107
|
+
date
|
108
|
+
net-protocol
|
109
|
+
net-pop (0.1.2)
|
110
|
+
net-protocol
|
111
|
+
net-protocol (0.2.1)
|
112
|
+
timeout
|
113
|
+
net-smtp (0.3.3)
|
114
|
+
net-protocol
|
115
|
+
nio4r (2.5.9)
|
116
|
+
nokogiri (1.14.3-x86_64-linux)
|
94
117
|
racc (~> 1.4)
|
95
118
|
observr (1.0.5)
|
96
|
-
parallel (1.
|
97
|
-
parser (3.
|
119
|
+
parallel (1.22.1)
|
120
|
+
parser (3.2.2.0)
|
98
121
|
ast (~> 2.4.1)
|
99
|
-
racc (1.
|
100
|
-
rack (2.2.
|
101
|
-
rack-test (
|
102
|
-
rack (>= 1.
|
103
|
-
rails (
|
104
|
-
actioncable (=
|
105
|
-
actionmailbox (=
|
106
|
-
actionmailer (=
|
107
|
-
actionpack (=
|
108
|
-
actiontext (=
|
109
|
-
actionview (=
|
110
|
-
activejob (=
|
111
|
-
activemodel (=
|
112
|
-
activerecord (=
|
113
|
-
activestorage (=
|
114
|
-
activesupport (=
|
122
|
+
racc (1.6.2)
|
123
|
+
rack (2.2.6.4)
|
124
|
+
rack-test (2.1.0)
|
125
|
+
rack (>= 1.3)
|
126
|
+
rails (7.0.4.3)
|
127
|
+
actioncable (= 7.0.4.3)
|
128
|
+
actionmailbox (= 7.0.4.3)
|
129
|
+
actionmailer (= 7.0.4.3)
|
130
|
+
actionpack (= 7.0.4.3)
|
131
|
+
actiontext (= 7.0.4.3)
|
132
|
+
actionview (= 7.0.4.3)
|
133
|
+
activejob (= 7.0.4.3)
|
134
|
+
activemodel (= 7.0.4.3)
|
135
|
+
activerecord (= 7.0.4.3)
|
136
|
+
activestorage (= 7.0.4.3)
|
137
|
+
activesupport (= 7.0.4.3)
|
115
138
|
bundler (>= 1.15.0)
|
116
|
-
railties (=
|
117
|
-
sprockets-rails (>= 2.0.0)
|
139
|
+
railties (= 7.0.4.3)
|
118
140
|
rails-dom-testing (2.0.3)
|
119
141
|
activesupport (>= 4.2.0)
|
120
142
|
nokogiri (>= 1.6)
|
121
|
-
rails-html-sanitizer (1.
|
122
|
-
loofah (~> 2.
|
123
|
-
railties (
|
124
|
-
actionpack (=
|
125
|
-
activesupport (=
|
143
|
+
rails-html-sanitizer (1.5.0)
|
144
|
+
loofah (~> 2.19, >= 2.19.1)
|
145
|
+
railties (7.0.4.3)
|
146
|
+
actionpack (= 7.0.4.3)
|
147
|
+
activesupport (= 7.0.4.3)
|
126
148
|
method_source
|
127
|
-
rake (>=
|
149
|
+
rake (>= 12.2)
|
128
150
|
thor (~> 1.0)
|
129
|
-
|
130
|
-
|
131
|
-
|
151
|
+
zeitwerk (~> 2.5)
|
152
|
+
rainbow (3.1.1)
|
153
|
+
rake (13.0.6)
|
154
|
+
regexp_parser (2.7.0)
|
132
155
|
rexml (3.2.5)
|
133
|
-
|
156
|
+
ricecream (0.2.1)
|
157
|
+
rubocop (1.48.1)
|
158
|
+
json (~> 2.3)
|
134
159
|
parallel (~> 1.10)
|
135
|
-
parser (>= 3.
|
160
|
+
parser (>= 3.2.0.0)
|
136
161
|
rainbow (>= 2.2.2, < 4.0)
|
137
162
|
regexp_parser (>= 1.8, < 3.0)
|
138
|
-
rexml
|
139
|
-
rubocop-ast (>= 1.
|
163
|
+
rexml (>= 3.2.5, < 4.0)
|
164
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
140
165
|
ruby-progressbar (~> 1.7)
|
141
|
-
unicode-display_width (>=
|
142
|
-
rubocop-ast (1.
|
143
|
-
parser (>= 3.
|
144
|
-
|
145
|
-
|
166
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
167
|
+
rubocop-ast (1.28.0)
|
168
|
+
parser (>= 3.2.1.0)
|
169
|
+
rubocop-performance (1.16.0)
|
170
|
+
rubocop (>= 1.7.0, < 2.0)
|
171
|
+
rubocop-ast (>= 0.4.0)
|
172
|
+
ruby-progressbar (1.13.0)
|
173
|
+
simplecov (0.22.0)
|
146
174
|
docile (~> 1.1)
|
147
175
|
simplecov-html (~> 0.11)
|
148
176
|
simplecov_json_formatter (~> 0.1)
|
149
177
|
simplecov-html (0.12.3)
|
150
|
-
simplecov_json_formatter (0.1.
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
thor (1.1.0)
|
160
|
-
tzinfo (2.0.4)
|
178
|
+
simplecov_json_formatter (0.1.4)
|
179
|
+
sqlite3 (1.6.2-x86_64-linux)
|
180
|
+
standard (1.26.0)
|
181
|
+
language_server-protocol (~> 3.17.0.2)
|
182
|
+
rubocop (~> 1.48.1)
|
183
|
+
rubocop-performance (~> 1.16.0)
|
184
|
+
thor (1.2.1)
|
185
|
+
timeout (0.3.2)
|
186
|
+
tzinfo (2.0.6)
|
161
187
|
concurrent-ruby (~> 1.0)
|
162
|
-
unicode-display_width (2.
|
188
|
+
unicode-display_width (2.4.2)
|
163
189
|
websocket-driver (0.7.5)
|
164
190
|
websocket-extensions (>= 0.1.0)
|
165
191
|
websocket-extensions (0.1.5)
|
166
|
-
zeitwerk (2.
|
192
|
+
zeitwerk (2.6.7)
|
167
193
|
|
168
194
|
PLATFORMS
|
169
195
|
x86_64-linux
|
170
196
|
|
171
197
|
DEPENDENCIES
|
172
|
-
|
173
|
-
bundler
|
198
|
+
combustion
|
174
199
|
minitest
|
200
|
+
minitest-spec-rails
|
175
201
|
observr
|
176
202
|
rails
|
177
|
-
rake
|
178
203
|
relation!
|
179
|
-
|
204
|
+
ricecream
|
180
205
|
simplecov
|
181
206
|
sqlite3
|
207
|
+
standard
|
182
208
|
|
183
209
|
BUNDLED WITH
|
184
|
-
2.
|
210
|
+
2.4.10
|
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015-2023 Dittmar Krall (www.matiq.com)
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
6
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -4,8 +4,8 @@
|
|
4
4
|
AFAIK, Relation can replace all kind of relationships in a Rails database.
|
5
5
|
The gem stores the relationships in a additional table (named
|
6
6
|
"relations") containing
|
7
|
-
triples (name of relationship,
|
8
|
-
No additional column/field is required in a particular
|
7
|
+
triples (name of relationship, from_id, to_id).
|
8
|
+
No additional column/field is required in a particular table.
|
9
9
|
Adding/removing a relationship do not required a migration.
|
10
10
|
|
11
11
|
Is it recommendable? Well, you should know.
|
@@ -28,20 +28,17 @@ i.e. you are responsible for them.
|
|
28
28
|
## Installation
|
29
29
|
|
30
30
|
As usual:
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
# Gemfile file
|
37
|
-
gem 'relation'
|
38
|
-
|
39
|
-
$ bundle
|
31
|
+
``` ruby
|
32
|
+
# Gemfile
|
33
|
+
gem "relation"
|
34
|
+
```
|
35
|
+
and run "bundle install".
|
40
36
|
|
41
37
|
Furthermore the association table (an n-ways-join table) must be
|
42
38
|
installed and migrated.
|
43
|
-
You may copy the migration "db/migrate/
|
39
|
+
You may copy the migration "./db/migrate/003_create_relations.rb"
|
44
40
|
from the gem.
|
41
|
+
Add indexes if required (benchmarking give clues).
|
45
42
|
The migration is then done, as usual, by:
|
46
43
|
|
47
44
|
$ rails db:migrate
|
@@ -50,17 +47,19 @@ The migration is then done, as usual, by:
|
|
50
47
|
|
51
48
|
In short (order* and user* are instances of ActiveRecords):
|
52
49
|
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
``` ruby
|
51
|
+
Relation.add order, user
|
52
|
+
Relation.add order, user2
|
53
|
+
Relation.add order2, user2
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
Relation.references order, User # -> [user, user2]
|
56
|
+
Relation.references order2, User # -> [user2]
|
57
|
+
Relation.followers Order, user # -> [order]
|
58
|
+
Relation.followers Order, user2 # -> [order, order2]
|
61
59
|
|
62
|
-
|
63
|
-
|
60
|
+
Relation.delete order2, user2
|
61
|
+
Relation.followers Order, user2 # -> [order]
|
62
|
+
```
|
64
63
|
|
65
64
|
See also the tests.
|
66
65
|
|
@@ -76,15 +75,21 @@ and cleaned by:
|
|
76
75
|
|
77
76
|
Above mentioned methods are based on the following low level methods:
|
78
77
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
``` ruby
|
79
|
+
Relation.add_raw(name, from_id, to_id)
|
80
|
+
Relation.delete_raw(name, from_id, to_id)
|
81
|
+
Relation.references_raw(name, from_id)
|
82
|
+
Relation.followers_raw(name, to_id)
|
83
|
+
```
|
83
84
|
|
84
85
|
They may be used for relationships which can not be based on the
|
85
86
|
class name of the ActiveRecords.
|
86
87
|
Keep in mind that dangling relations must be handled by yourself.
|
87
88
|
|
89
|
+
** Version 4
|
90
|
+
|
91
|
+
Version 4.+ is intended for Rails 7.
|
92
|
+
|
88
93
|
## Rails 6
|
89
94
|
|
90
95
|
This gem is intended for Rails 6.
|
@@ -92,4 +97,9 @@ Rails 5 should work fine.
|
|
92
97
|
|
93
98
|
Older Rails versions may use "gem 'relation', '= 0.1.1'".
|
94
99
|
|
95
|
-
##
|
100
|
+
## Miscellaneous
|
101
|
+
|
102
|
+
Copyright (c) 2015-2023 Dittmar Krall (www.matiq.com),
|
103
|
+
released under the MIT license:
|
104
|
+
|
105
|
+
* https://opensource.org/licenses/MIT
|
data/Rakefile
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "rake/testtask"
|
2
2
|
|
3
|
-
desc
|
3
|
+
desc "Run the tests."
|
4
4
|
Rake::TestTask.new do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.pattern =
|
5
|
+
t.libs << "lib"
|
6
|
+
t.libs << "test"
|
7
|
+
t.pattern = "test/**/*_test.rb"
|
8
8
|
t.verbose = false
|
9
9
|
end
|
10
10
|
|
data/app/models/dangling.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Relation < ActiveRecord::Base
|
4
|
+
# dangling relations
|
4
5
|
def self.dangling
|
5
6
|
names = Relation.pluck(:name).uniq
|
6
7
|
models = []
|
7
|
-
names.each { |name| models |= name.split(
|
8
|
+
names.each { |name| models |= name.split(" ") }
|
8
9
|
hsh = {}
|
9
10
|
models.each do |class_name|
|
10
11
|
klass = class_name.constantize
|
11
12
|
ids = klass.pluck(:id)
|
12
|
-
idx = Relation.where(
|
13
|
-
idy = Relation.where(
|
13
|
+
idx = Relation.where("name like ?", "#{class_name} %").pluck(:from_id)
|
14
|
+
idy = Relation.where("name like ?", "% #{class_name}").pluck(:to_id)
|
14
15
|
arr = (idx | idy) - ids
|
15
16
|
hsh[class_name] = arr if arr.length.positive?
|
16
17
|
end
|
@@ -20,8 +21,8 @@ class Relation < ActiveRecord::Base
|
|
20
21
|
def self.remove_dangling(hsh)
|
21
22
|
hsh.each do |name, arr|
|
22
23
|
arr.each do |idx|
|
23
|
-
Relation.where(from_id: idx).where(
|
24
|
-
Relation.where(to_id: idx).where(
|
24
|
+
Relation.where(from_id: idx).where("name like ?", "#{name} %").delete_all
|
25
|
+
Relation.where(to_id: idx).where("name like ?", "% #{name}").delete_all
|
25
26
|
end
|
26
27
|
end
|
27
28
|
end
|
data/app/models/relation.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Relation < ActiveRecord::Base
|
2
4
|
def self.add_raw(name, from_id, to_id)
|
3
|
-
hsh = {
|
5
|
+
hsh = {name: name, from_id: from_id, to_id: to_id}
|
4
6
|
Relation.create!(hsh) if Relation.where(hsh).first.nil?
|
5
7
|
end
|
6
8
|
|
7
9
|
def self.delete_raw(name, from_id, to_id)
|
8
|
-
hsh = {
|
10
|
+
hsh = {name: name, from_id: from_id, to_id: to_id}
|
9
11
|
Relation.where(hsh).delete_all
|
10
12
|
end
|
11
13
|
|
data/app/models/relation_ext.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
class Relation < ActiveRecord::Base
|
4
|
+
# extended Relation
|
3
5
|
def self.add(row_from, row_to)
|
4
6
|
hsh = normalize(row_from, row_to)
|
5
7
|
Relation.create!(hsh) if Relation.where(hsh).first.nil?
|
@@ -25,16 +27,16 @@ class Relation < ActiveRecord::Base
|
|
25
27
|
end
|
26
28
|
|
27
29
|
def self.name_id(resource)
|
28
|
-
raise
|
30
|
+
raise "missing resource" unless resource
|
29
31
|
|
30
32
|
[resource.class.name, resource.id]
|
31
33
|
end
|
32
34
|
|
33
35
|
def self.normalize(row_from, row_to)
|
34
36
|
name_from, from_id = name_id(row_from)
|
35
|
-
name_to, to_id
|
37
|
+
name_to, to_id = name_id(row_to)
|
36
38
|
name = "#{name_from} #{name_to}"
|
37
|
-
{
|
39
|
+
{name: name, from_id: from_id, to_id: to_id}
|
38
40
|
end
|
39
41
|
|
40
42
|
def self.normalize2(kind, row)
|
@@ -1,7 +1,7 @@
|
|
1
|
-
class CreateRelations < ActiveRecord::Migration[
|
1
|
+
class CreateRelations < ActiveRecord::Migration[7.0]
|
2
2
|
def change
|
3
3
|
create_table :relations, id: false do |t|
|
4
|
-
t.string
|
4
|
+
t.string :name
|
5
5
|
t.references :from, null: false
|
6
6
|
t.references :to, null: false
|
7
7
|
t.timestamps
|
data/lib/relation/engine.rb
CHANGED
@@ -1,26 +1,4 @@
|
|
1
|
-
# rubocop: disable all
|
2
|
-
|
3
1
|
module ModRelation
|
4
|
-
class Engine < Rails::Engine
|
5
|
-
isolate_namespace ModRelation
|
6
|
-
|
7
|
-
# # https://github.com/rails/rails/issues/22261
|
8
|
-
# initializer :append_migrations do |app|
|
9
|
-
# config.paths['db/migrate'].expanded.each do |path|
|
10
|
-
# app.config.paths['db/migrate'] << path
|
11
|
-
# ActiveRecord::Migrator.migrations_paths << path
|
12
|
-
# end
|
13
|
-
# end
|
14
|
-
|
15
|
-
# # https://github.com/rails/rails/issues/22261
|
16
|
-
# module ActiveRecord
|
17
|
-
# #module ActiveRecord::Current
|
18
|
-
# class Schema < Migration
|
19
|
-
# def migrations_paths
|
20
|
-
# (ActiveRecord::Migrator.migrations_paths +
|
21
|
-
# Rails.application.paths['db/migrate'].to_a).uniq
|
22
|
-
# end
|
23
|
-
# end
|
24
|
-
# end
|
2
|
+
class Engine < ::Rails::Engine
|
25
3
|
end
|
26
4
|
end
|