relation 0.3.8 → 0.4.2
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 +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 +139 -111
- data/MIT-LICENSE +3 -1
- data/README.md +35 -25
- 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 +12 -9
- data/lib/relation.rb +3 -6
- data/relation.gemspec +19 -24
- 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 +17 -32
- 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: dad2321dbb5e4ef524d79ca664f20f7a1d23831de4272adaf0e0327629cada11
|
4
|
+
data.tar.gz: 4e2662c4c9aaaa281d95b06e0ef8e231350c13c81cef3519b545cb8472d9bcff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1bec683b5a73845826e1c06c0449c29ad308ab8246565df5e4c22e2f8a58635cd0fcb6940d8fb4d9e17d7b271df96326cf47be1701a2a0d94ebd69c6bf7b8b9
|
7
|
+
data.tar.gz: 17177607e1e03c3159de5d73eeff1ee5577ccbd93166998b667f028272a3ba0d4834e6e867c054e78fb3a6d994c172724a3acb6c3ec4ae51a8f8d4c29b0e6d11
|
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.0
|
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,212 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
relation (0.
|
5
|
-
activerecord
|
4
|
+
relation (0.4.2)
|
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.1)
|
10
|
+
actionpack (= 7.0.4.1)
|
11
|
+
activesupport (= 7.0.4.1)
|
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.1)
|
15
|
+
actionpack (= 7.0.4.1)
|
16
|
+
activejob (= 7.0.4.1)
|
17
|
+
activerecord (= 7.0.4.1)
|
18
|
+
activestorage (= 7.0.4.1)
|
19
|
+
activesupport (= 7.0.4.1)
|
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.1)
|
25
|
+
actionpack (= 7.0.4.1)
|
26
|
+
actionview (= 7.0.4.1)
|
27
|
+
activejob (= 7.0.4.1)
|
28
|
+
activesupport (= 7.0.4.1)
|
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.1)
|
35
|
+
actionview (= 7.0.4.1)
|
36
|
+
activesupport (= 7.0.4.1)
|
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.1)
|
42
|
+
actionpack (= 7.0.4.1)
|
43
|
+
activerecord (= 7.0.4.1)
|
44
|
+
activestorage (= 7.0.4.1)
|
45
|
+
activesupport (= 7.0.4.1)
|
46
|
+
globalid (>= 0.6.0)
|
41
47
|
nokogiri (>= 1.8.5)
|
42
|
-
actionview (
|
43
|
-
activesupport (=
|
48
|
+
actionview (7.0.4.1)
|
49
|
+
activesupport (= 7.0.4.1)
|
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.1)
|
55
|
+
activesupport (= 7.0.4.1)
|
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.1)
|
58
|
+
activesupport (= 7.0.4.1)
|
59
|
+
activerecord (7.0.4.1)
|
60
|
+
activemodel (= 7.0.4.1)
|
61
|
+
activesupport (= 7.0.4.1)
|
62
|
+
activestorage (7.0.4.1)
|
63
|
+
actionpack (= 7.0.4.1)
|
64
|
+
activejob (= 7.0.4.1)
|
65
|
+
activerecord (= 7.0.4.1)
|
66
|
+
activesupport (= 7.0.4.1)
|
67
|
+
marcel (~> 1.0)
|
68
|
+
mini_mime (>= 1.1.0)
|
69
|
+
activesupport (7.0.4.1)
|
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.1.10)
|
76
81
|
crass (1.0.6)
|
82
|
+
date (3.3.3)
|
77
83
|
docile (1.4.0)
|
78
|
-
erubi (1.
|
79
|
-
globalid (0.
|
80
|
-
activesupport (>=
|
81
|
-
i18n (1.
|
84
|
+
erubi (1.12.0)
|
85
|
+
globalid (1.0.1)
|
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.2)
|
91
|
+
loofah (2.19.1)
|
84
92
|
crass (~> 1.0.2)
|
85
93
|
nokogiri (>= 1.5.9)
|
86
|
-
mail (2.
|
94
|
+
mail (2.8.0.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.17.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.8)
|
116
|
+
nokogiri (1.14.0-x86_64-linux)
|
94
117
|
racc (~> 1.4)
|
95
118
|
observr (1.0.5)
|
96
|
-
parallel (1.
|
97
|
-
parser (3.0.
|
119
|
+
parallel (1.22.1)
|
120
|
+
parser (3.2.0.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.2)
|
124
|
+
rack-test (2.0.2)
|
125
|
+
rack (>= 1.3)
|
126
|
+
rails (7.0.4.1)
|
127
|
+
actioncable (= 7.0.4.1)
|
128
|
+
actionmailbox (= 7.0.4.1)
|
129
|
+
actionmailer (= 7.0.4.1)
|
130
|
+
actionpack (= 7.0.4.1)
|
131
|
+
actiontext (= 7.0.4.1)
|
132
|
+
actionview (= 7.0.4.1)
|
133
|
+
activejob (= 7.0.4.1)
|
134
|
+
activemodel (= 7.0.4.1)
|
135
|
+
activerecord (= 7.0.4.1)
|
136
|
+
activestorage (= 7.0.4.1)
|
137
|
+
activesupport (= 7.0.4.1)
|
115
138
|
bundler (>= 1.15.0)
|
116
|
-
railties (=
|
117
|
-
sprockets-rails (>= 2.0.0)
|
139
|
+
railties (= 7.0.4.1)
|
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.4.4)
|
144
|
+
loofah (~> 2.19, >= 2.19.1)
|
145
|
+
railties (7.0.4.1)
|
146
|
+
actionpack (= 7.0.4.1)
|
147
|
+
activesupport (= 7.0.4.1)
|
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.6.1)
|
132
155
|
rexml (3.2.5)
|
133
|
-
|
156
|
+
ricecream (0.2.1)
|
157
|
+
rubocop (1.42.0)
|
158
|
+
json (~> 2.3)
|
134
159
|
parallel (~> 1.10)
|
135
|
-
parser (>= 3.
|
160
|
+
parser (>= 3.1.2.1)
|
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.24.1, < 2.0)
|
140
165
|
ruby-progressbar (~> 1.7)
|
141
166
|
unicode-display_width (>= 1.4.0, < 3.0)
|
142
|
-
rubocop-ast (1.
|
143
|
-
parser (>= 3.
|
167
|
+
rubocop-ast (1.24.1)
|
168
|
+
parser (>= 3.1.1.0)
|
169
|
+
rubocop-performance (1.15.2)
|
170
|
+
rubocop (>= 1.7.0, < 2.0)
|
171
|
+
rubocop-ast (>= 0.4.0)
|
144
172
|
ruby-progressbar (1.11.0)
|
145
|
-
simplecov (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.0-x86_64-linux)
|
180
|
+
standard (1.22.0)
|
181
|
+
language_server-protocol (~> 3.17.0.2)
|
182
|
+
rubocop (= 1.42.0)
|
183
|
+
rubocop-performance (= 1.15.2)
|
184
|
+
thor (1.2.1)
|
185
|
+
timeout (0.3.1)
|
186
|
+
tzinfo (2.0.5)
|
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.6)
|
167
193
|
|
168
194
|
PLATFORMS
|
169
195
|
x86_64-linux
|
170
196
|
|
171
197
|
DEPENDENCIES
|
172
|
-
appraisal
|
173
198
|
bundler
|
199
|
+
combustion
|
174
200
|
minitest
|
201
|
+
minitest-spec-rails
|
175
202
|
observr
|
176
203
|
rails
|
177
204
|
rake
|
178
205
|
relation!
|
179
|
-
|
206
|
+
ricecream
|
180
207
|
simplecov
|
181
208
|
sqlite3
|
209
|
+
standard
|
182
210
|
|
183
211
|
BUNDLED WITH
|
184
|
-
2.
|
212
|
+
2.4.1
|
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
@@ -5,7 +5,7 @@ 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
7
|
triples (name of relationship, from:id, to_id).
|
8
|
-
No additional column/field is required in a particular
|
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
|