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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 853bc18cefd0604f0b9292840ea11d6ba76ec7375bf0d9802cf078f61c7b4823
4
- data.tar.gz: 82bb8714278faf2abe55bcae1387443783e1fec691dc54c1bc0585991b2d90f2
3
+ metadata.gz: dad2321dbb5e4ef524d79ca664f20f7a1d23831de4272adaf0e0327629cada11
4
+ data.tar.gz: 4e2662c4c9aaaa281d95b06e0ef8e231350c13c81cef3519b545cb8472d9bcff
5
5
  SHA512:
6
- metadata.gz: 5b25cebb6364b1978bcc3c447adb9407d31d191483c26adc3da12eae5dda385d00ab250476de1775bb9101ea1b60a41c79b9f6aad03f6512f6ed812c0292a722
7
- data.tar.gz: 5f2f0501587bb4b3cdba3b9190759ed6ed0fedc4da7938dcba4f0693eab3d5a989c32ede95accf0d59b2224cf215e38d6f8cb9252ba4396d3341f9f58b48a2d3
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
@@ -8,4 +8,4 @@ coverage/
8
8
  **/*.gem
9
9
  **/*.log
10
10
  **/*.lock
11
- **/*.sqlite3
11
+ **/*.sqlite3*
data/.ruby-gemset CHANGED
@@ -1 +1 @@
1
- rails-6.0
1
+ rails-7.0
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.6.6
1
+ ruby-3.2.0
data/Gemfile CHANGED
@@ -1,10 +1,12 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
- gem 'rails'
4
+ gem "rails"
5
5
 
6
6
  group :test do
7
- gem 'observr'
8
- gem 'rubocop', require: false
9
- gem 'simplecov', require: false
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.3.7)
5
- activerecord (~> 6)
4
+ relation (0.4.2)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
9
8
  specs:
10
- actioncable (6.0.3.2)
11
- actionpack (= 6.0.3.2)
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 (6.0.3.2)
15
- actionpack (= 6.0.3.2)
16
- activejob (= 6.0.3.2)
17
- activerecord (= 6.0.3.2)
18
- activestorage (= 6.0.3.2)
19
- activesupport (= 6.0.3.2)
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
- actionmailer (6.0.3.2)
22
- actionpack (= 6.0.3.2)
23
- actionview (= 6.0.3.2)
24
- activejob (= 6.0.3.2)
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 (6.0.3.2)
28
- actionview (= 6.0.3.2)
29
- activesupport (= 6.0.3.2)
30
- rack (~> 2.0, >= 2.0.8)
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 (6.0.3.2)
35
- actionpack (= 6.0.3.2)
36
- activerecord (= 6.0.3.2)
37
- activestorage (= 6.0.3.2)
38
- activesupport (= 6.0.3.2)
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 (6.0.3.2)
41
- activesupport (= 6.0.3.2)
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 (6.0.3.2)
47
- activesupport (= 6.0.3.2)
54
+ activejob (7.0.4.1)
55
+ activesupport (= 7.0.4.1)
48
56
  globalid (>= 0.3.6)
49
- activemodel (6.0.3.2)
50
- activesupport (= 6.0.3.2)
51
- activerecord (6.0.3.2)
52
- activemodel (= 6.0.3.2)
53
- activesupport (= 6.0.3.2)
54
- activestorage (6.0.3.2)
55
- actionpack (= 6.0.3.2)
56
- activejob (= 6.0.3.2)
57
- activerecord (= 6.0.3.2)
58
- marcel (~> 0.3.1)
59
- activesupport (6.0.3.2)
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 (>= 0.7, < 2)
62
- minitest (~> 5.1)
63
- tzinfo (~> 1.1)
64
- zeitwerk (~> 2.2, >= 2.2.2)
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
- concurrent-ruby (1.1.6)
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
- docile (1.3.2)
74
- erubi (1.9.0)
75
- globalid (0.4.2)
76
- activesupport (>= 4.2.0)
77
- i18n (1.8.3)
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
- loofah (2.6.0)
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.7.1)
94
+ mail (2.8.0.1)
83
95
  mini_mime (>= 0.1.1)
84
- marcel (0.3.3)
85
- mimemagic (~> 0.3.2)
96
+ net-imap
97
+ net-pop
98
+ net-smtp
99
+ marcel (1.0.2)
86
100
  method_source (1.0.0)
87
- mimemagic (0.3.5)
88
- mini_mime (1.0.2)
89
- mini_portile2 (2.4.0)
90
- minitest (5.14.1)
91
- nio4r (2.5.2)
92
- nokogiri (1.10.10)
93
- mini_portile2 (~> 2.4.0)
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.19.2)
96
- parser (2.7.1.4)
119
+ parallel (1.22.1)
120
+ parser (3.2.0.0)
97
121
  ast (~> 2.4.1)
98
- rack (2.2.3)
99
- rack-test (1.1.0)
100
- rack (>= 1.0, < 3)
101
- rails (6.0.3.2)
102
- actioncable (= 6.0.3.2)
103
- actionmailbox (= 6.0.3.2)
104
- actionmailer (= 6.0.3.2)
105
- actionpack (= 6.0.3.2)
106
- actiontext (= 6.0.3.2)
107
- actionview (= 6.0.3.2)
108
- activejob (= 6.0.3.2)
109
- activemodel (= 6.0.3.2)
110
- activerecord (= 6.0.3.2)
111
- activestorage (= 6.0.3.2)
112
- activesupport (= 6.0.3.2)
113
- bundler (>= 1.3.0)
114
- railties (= 6.0.3.2)
115
- sprockets-rails (>= 2.0.0)
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.3.0)
120
- loofah (~> 2.3)
121
- railties (6.0.3.2)
122
- actionpack (= 6.0.3.2)
123
- activesupport (= 6.0.3.2)
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 (>= 0.8.7)
126
- thor (>= 0.20.3, < 2.0)
127
- rainbow (3.0.0)
128
- rake (13.0.1)
129
- regexp_parser (1.7.1)
130
- rexml (3.2.4)
131
- rubocop (0.88.0)
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 (>= 2.7.1.1)
160
+ parser (>= 3.1.2.1)
134
161
  rainbow (>= 2.2.2, < 4.0)
135
- regexp_parser (>= 1.7)
136
- rexml
137
- rubocop-ast (>= 0.1.0, < 1.0)
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, < 2.0)
140
- rubocop-ast (0.1.0)
141
- parser (>= 2.7.0.1)
142
- ruby-progressbar (1.10.1)
143
- simplecov (0.18.5)
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
- simplecov-html (0.12.2)
147
- sprockets (4.0.2)
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
- rack (> 1, < 3)
150
- sprockets-rails (3.2.1)
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.3.1)
192
+ zeitwerk (2.6.6)
164
193
 
165
194
  PLATFORMS
166
- ruby
195
+ x86_64-linux
167
196
 
168
197
  DEPENDENCIES
169
- appraisal (~> 2)
170
- bundler (~> 1)
171
- minitest (~> 5)
198
+ bundler
199
+ combustion
200
+ minitest
201
+ minitest-spec-rails
172
202
  observr
173
203
  rails
174
- rake (~> 13)
204
+ rake
175
205
  relation!
176
- rubocop
206
+ ricecream
177
207
  simplecov
178
- sqlite3 (~> 1)
208
+ sqlite3
209
+ standard
179
210
 
180
211
  BUNDLED WITH
181
- 1.17.3
212
+ 2.4.1
data/MIT-LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright 2015-2020 Dittmar Krall - www.matique.com
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 tables.
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
- $ [sudo] gem install relation
34
-
35
- or:
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/20150810152808_relation.rb"
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
- Relation.add order, user
55
- Relation.add order, user2
56
- Relation.add order2, user2
50
+ ``` ruby
51
+ Relation.add order, user
52
+ Relation.add order, user2
53
+ Relation.add order2, user2
57
54
 
58
- Relation.references order, User # -> [user, user2]
59
- Relation.references order2, User # -> [user2]
60
- Relation.followers Order, user # -> [order]
61
- Relation.followers Order, user2 # -> [order, order2]
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
- Relation.delete order2, user2
64
- Relation.followers Order, user2 # -> [order]
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
- Relation.add_raw(name, from_id, to_id)
81
- Relation.delete_raw(name, from_id, to_id)
82
- Relation.references_raw(name, from_id)
83
- Relation.followers_raw(name, to_id)
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
- ## License MIT
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 'rake/testtask'
1
+ require "rake/testtask"
2
2
 
3
- desc 'Run the tests.'
3
+ desc "Run the tests."
4
4
  Rake::TestTask.new do |t|
5
- t.libs << 'lib'
6
- t.libs << 'test'
7
- t.pattern = 'test/**/*_test.rb'
5
+ t.libs << "lib"
6
+ t.libs << "test"
7
+ t.pattern = "test/**/*_test.rb"
8
8
  t.verbose = false
9
9
  end
10
10
 
@@ -1,16 +1,17 @@
1
- # extended Relation: extracts relation from rows
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('name like ?', "#{class_name} %").pluck(:from_id)
13
- idy = Relation.where('name like ?', "% #{class_name}").pluck(:to_id)
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('name like ?', "#{name} %").delete_all
24
- Relation.where(to_id: idx).where('name like ?', "% #{name}").delete_all
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
@@ -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 = { name: name, from_id: from_id, to_id: to_id }
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 = { name: name, from_id: from_id, to_id: to_id }
10
+ hsh = {name: name, from_id: from_id, to_id: to_id}
9
11
  Relation.where(hsh).delete_all
10
12
  end
11
13
 
@@ -1,5 +1,7 @@
1
- # extended Relation: extracts relation from rows
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 'missing resource' unless resource
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 = name_id(row_to)
37
+ name_to, to_id = name_id(row_to)
36
38
  name = "#{name_from} #{name_to}"
37
- { name: name, from_id: from_id, to_id: to_id }
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[5.2]
1
+ class CreateRelations < ActiveRecord::Migration[7.0]
2
2
  def change
3
3
  create_table :relations, id: false do |t|
4
- t.string :name
4
+ t.string :name
5
5
  t.references :from, null: false
6
6
  t.references :to, null: false
7
7
  t.timestamps