relation 0.3.7 → 0.4.2
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 +26 -0
- data/.gitignore +1 -1
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/Gemfile +7 -5
- data/Gemfile.lock +159 -128
- data/MIT-LICENSE +3 -1
- data/README.md +35 -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 +12 -8
- data/lib/relation.rb +3 -6
- data/relation.gemspec +19 -23
- 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 +40 -54
- data/.rubocop.yml +0 -8
- data/.travis.yml +0 -43
- data/.watchr +0 -48
- data/Appraisals +0 -15
- data/gemfiles/rails_5.2.gemfile +0 -11
- data/gemfiles/rails_6.0.gemfile +0 -11
- 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
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# see also https://github.com/whitequark/parser/blob/master/.github/workflows/test.yml
|
2
|
+
name: Rake
|
3
|
+
|
4
|
+
on: [push]
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
test:
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
os: [ubuntu-latest]
|
12
|
+
ruby: ["2.7", "3.0", "3.2", head]
|
13
|
+
test_command: ["bundle exec rake"]
|
14
|
+
runs-on: ${{ matrix.os }}
|
15
|
+
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v3
|
18
|
+
- uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby }}
|
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,181 +1,212 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
relation (0.
|
5
|
-
activerecord (~> 6)
|
4
|
+
relation (0.4.2)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
9
8
|
specs:
|
10
|
-
actioncable (
|
11
|
-
actionpack (=
|
9
|
+
actioncable (7.0.4.1)
|
10
|
+
actionpack (= 7.0.4.1)
|
11
|
+
activesupport (= 7.0.4.1)
|
12
12
|
nio4r (~> 2.0)
|
13
13
|
websocket-driver (>= 0.6.1)
|
14
|
-
actionmailbox (
|
15
|
-
actionpack (=
|
16
|
-
activejob (=
|
17
|
-
activerecord (=
|
18
|
-
activestorage (=
|
19
|
-
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)
|
20
20
|
mail (>= 2.7.1)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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)
|
25
29
|
mail (~> 2.5, >= 2.5.4)
|
30
|
+
net-imap
|
31
|
+
net-pop
|
32
|
+
net-smtp
|
26
33
|
rails-dom-testing (~> 2.0)
|
27
|
-
actionpack (
|
28
|
-
actionview (=
|
29
|
-
activesupport (=
|
30
|
-
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)
|
31
38
|
rack-test (>= 0.6.3)
|
32
39
|
rails-dom-testing (~> 2.0)
|
33
40
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
34
|
-
actiontext (
|
35
|
-
actionpack (=
|
36
|
-
activerecord (=
|
37
|
-
activestorage (=
|
38
|
-
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)
|
39
47
|
nokogiri (>= 1.8.5)
|
40
|
-
actionview (
|
41
|
-
activesupport (=
|
48
|
+
actionview (7.0.4.1)
|
49
|
+
activesupport (= 7.0.4.1)
|
42
50
|
builder (~> 3.1)
|
43
51
|
erubi (~> 1.4)
|
44
52
|
rails-dom-testing (~> 2.0)
|
45
53
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
46
|
-
activejob (
|
47
|
-
activesupport (=
|
54
|
+
activejob (7.0.4.1)
|
55
|
+
activesupport (= 7.0.4.1)
|
48
56
|
globalid (>= 0.3.6)
|
49
|
-
activemodel (
|
50
|
-
activesupport (=
|
51
|
-
activerecord (
|
52
|
-
activemodel (=
|
53
|
-
activesupport (=
|
54
|
-
activestorage (
|
55
|
-
actionpack (=
|
56
|
-
activejob (=
|
57
|
-
activerecord (=
|
58
|
-
|
59
|
-
|
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)
|
60
70
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
61
|
-
i18n (>=
|
62
|
-
minitest (
|
63
|
-
tzinfo (~>
|
64
|
-
|
65
|
-
appraisal (2.3.0)
|
66
|
-
bundler
|
67
|
-
rake
|
68
|
-
thor (>= 0.14.0)
|
69
|
-
ast (2.4.1)
|
71
|
+
i18n (>= 1.6, < 2)
|
72
|
+
minitest (>= 5.1)
|
73
|
+
tzinfo (~> 2.0)
|
74
|
+
ast (2.4.2)
|
70
75
|
builder (3.2.4)
|
71
|
-
|
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)
|
72
81
|
crass (1.0.6)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
82
|
+
date (3.3.3)
|
83
|
+
docile (1.4.0)
|
84
|
+
erubi (1.12.0)
|
85
|
+
globalid (1.0.1)
|
86
|
+
activesupport (>= 5.0)
|
87
|
+
i18n (1.12.0)
|
78
88
|
concurrent-ruby (~> 1.0)
|
79
|
-
|
89
|
+
json (2.6.3)
|
90
|
+
language_server-protocol (3.17.0.2)
|
91
|
+
loofah (2.19.1)
|
80
92
|
crass (~> 1.0.2)
|
81
93
|
nokogiri (>= 1.5.9)
|
82
|
-
mail (2.
|
94
|
+
mail (2.8.0.1)
|
83
95
|
mini_mime (>= 0.1.1)
|
84
|
-
|
85
|
-
|
96
|
+
net-imap
|
97
|
+
net-pop
|
98
|
+
net-smtp
|
99
|
+
marcel (1.0.2)
|
86
100
|
method_source (1.0.0)
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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)
|
117
|
+
racc (~> 1.4)
|
94
118
|
observr (1.0.5)
|
95
|
-
parallel (1.
|
96
|
-
parser (2.
|
119
|
+
parallel (1.22.1)
|
120
|
+
parser (3.2.0.0)
|
97
121
|
ast (~> 2.4.1)
|
98
|
-
|
99
|
-
rack
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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)
|
138
|
+
bundler (>= 1.15.0)
|
139
|
+
railties (= 7.0.4.1)
|
116
140
|
rails-dom-testing (2.0.3)
|
117
141
|
activesupport (>= 4.2.0)
|
118
142
|
nokogiri (>= 1.6)
|
119
|
-
rails-html-sanitizer (1.
|
120
|
-
loofah (~> 2.
|
121
|
-
railties (
|
122
|
-
actionpack (=
|
123
|
-
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)
|
124
148
|
method_source
|
125
|
-
rake (>=
|
126
|
-
thor (
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
149
|
+
rake (>= 12.2)
|
150
|
+
thor (~> 1.0)
|
151
|
+
zeitwerk (~> 2.5)
|
152
|
+
rainbow (3.1.1)
|
153
|
+
rake (13.0.6)
|
154
|
+
regexp_parser (2.6.1)
|
155
|
+
rexml (3.2.5)
|
156
|
+
ricecream (0.2.1)
|
157
|
+
rubocop (1.42.0)
|
158
|
+
json (~> 2.3)
|
132
159
|
parallel (~> 1.10)
|
133
|
-
parser (>=
|
160
|
+
parser (>= 3.1.2.1)
|
134
161
|
rainbow (>= 2.2.2, < 4.0)
|
135
|
-
regexp_parser (>= 1.
|
136
|
-
rexml
|
137
|
-
rubocop-ast (>=
|
162
|
+
regexp_parser (>= 1.8, < 3.0)
|
163
|
+
rexml (>= 3.2.5, < 4.0)
|
164
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
138
165
|
ruby-progressbar (~> 1.7)
|
139
|
-
unicode-display_width (>= 1.4.0, <
|
140
|
-
rubocop-ast (
|
141
|
-
parser (>=
|
142
|
-
|
143
|
-
|
166
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
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)
|
172
|
+
ruby-progressbar (1.11.0)
|
173
|
+
simplecov (0.22.0)
|
144
174
|
docile (~> 1.1)
|
145
175
|
simplecov-html (~> 0.11)
|
146
|
-
|
147
|
-
|
176
|
+
simplecov_json_formatter (~> 0.1)
|
177
|
+
simplecov-html (0.12.3)
|
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)
|
148
187
|
concurrent-ruby (~> 1.0)
|
149
|
-
|
150
|
-
|
151
|
-
actionpack (>= 4.0)
|
152
|
-
activesupport (>= 4.0)
|
153
|
-
sprockets (>= 3.0.0)
|
154
|
-
sqlite3 (1.4.2)
|
155
|
-
thor (1.0.1)
|
156
|
-
thread_safe (0.3.6)
|
157
|
-
tzinfo (1.2.7)
|
158
|
-
thread_safe (~> 0.1)
|
159
|
-
unicode-display_width (1.7.0)
|
160
|
-
websocket-driver (0.7.3)
|
188
|
+
unicode-display_width (2.4.2)
|
189
|
+
websocket-driver (0.7.5)
|
161
190
|
websocket-extensions (>= 0.1.0)
|
162
191
|
websocket-extensions (0.1.5)
|
163
|
-
zeitwerk (2.
|
192
|
+
zeitwerk (2.6.6)
|
164
193
|
|
165
194
|
PLATFORMS
|
166
|
-
|
195
|
+
x86_64-linux
|
167
196
|
|
168
197
|
DEPENDENCIES
|
169
|
-
|
170
|
-
|
171
|
-
minitest
|
198
|
+
bundler
|
199
|
+
combustion
|
200
|
+
minitest
|
201
|
+
minitest-spec-rails
|
172
202
|
observr
|
173
203
|
rails
|
174
|
-
rake
|
204
|
+
rake
|
175
205
|
relation!
|
176
|
-
|
206
|
+
ricecream
|
177
207
|
simplecov
|
178
|
-
sqlite3
|
208
|
+
sqlite3
|
209
|
+
standard
|
179
210
|
|
180
211
|
BUNDLED WITH
|
181
|
-
|
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
@@ -1,12 +1,11 @@
|
|
1
1
|
# Relation
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/relation.png)](http://badge.fury.io/rb/relation)
|
3
|
-
[![Build Status](https://travis-ci.org/matique/relation.png?branch=master)](https://travis-ci.org/matique/relation)
|
4
3
|
|
5
4
|
AFAIK, Relation can replace all kind of relationships in a Rails database.
|
6
5
|
The gem stores the relationships in a additional table (named
|
7
6
|
"relations") containing
|
8
7
|
triples (name of relationship, from:id, to_id).
|
9
|
-
No additional column/field is required in a particular
|
8
|
+
No additional column/field is required in a particular table.
|
10
9
|
Adding/removing a relationship do not required a migration.
|
11
10
|
|
12
11
|
Is it recommendable? Well, you should know.
|
@@ -29,20 +28,17 @@ i.e. you are responsible for them.
|
|
29
28
|
## Installation
|
30
29
|
|
31
30
|
As usual:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
# Gemfile file
|
38
|
-
gem 'relation'
|
39
|
-
|
40
|
-
$ bundle
|
31
|
+
``` ruby
|
32
|
+
# Gemfile
|
33
|
+
gem "relation"
|
34
|
+
```
|
35
|
+
and run "bundle install".
|
41
36
|
|
42
37
|
Furthermore the association table (an n-ways-join table) must be
|
43
38
|
installed and migrated.
|
44
|
-
You may copy the migration "db/migrate/
|
39
|
+
You may copy the migration "./db/migrate/003_create_relations.rb"
|
45
40
|
from the gem.
|
41
|
+
Add indexes if required (benchmarking give clues).
|
46
42
|
The migration is then done, as usual, by:
|
47
43
|
|
48
44
|
$ rails db:migrate
|
@@ -51,17 +47,19 @@ The migration is then done, as usual, by:
|
|
51
47
|
|
52
48
|
In short (order* and user* are instances of ActiveRecords):
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
``` ruby
|
51
|
+
Relation.add order, user
|
52
|
+
Relation.add order, user2
|
53
|
+
Relation.add order2, user2
|
57
54
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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]
|
62
59
|
|
63
|
-
|
64
|
-
|
60
|
+
Relation.delete order2, user2
|
61
|
+
Relation.followers Order, user2 # -> [order]
|
62
|
+
```
|
65
63
|
|
66
64
|
See also the tests.
|
67
65
|
|
@@ -77,15 +75,21 @@ and cleaned by:
|
|
77
75
|
|
78
76
|
Above mentioned methods are based on the following low level methods:
|
79
77
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
+
```
|
84
84
|
|
85
85
|
They may be used for relationships which can not be based on the
|
86
86
|
class name of the ActiveRecords.
|
87
87
|
Keep in mind that dangling relations must be handled by yourself.
|
88
88
|
|
89
|
+
** Version 4
|
90
|
+
|
91
|
+
Version 4.+ is intended for Rails 7.
|
92
|
+
|
89
93
|
## Rails 6
|
90
94
|
|
91
95
|
This gem is intended for Rails 6.
|
@@ -93,4 +97,9 @@ Rails 5 should work fine.
|
|
93
97
|
|
94
98
|
Older Rails versions may use "gem 'relation', '= 0.1.1'".
|
95
99
|
|
96
|
-
##
|
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
|