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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e1f65b86857cd18b3d25cee2c73dd2e6a8774a1e462ff4a014713a8aa14d623
4
- data.tar.gz: b9a57c23c9a5e2c035f7745a9ef5738a0bedd84f1489b168cd8b4c8c1438c93e
3
+ metadata.gz: dafdb00f20ba4c9fbd3e810ec8fd5abbea1c8b20ce27a5f9b0d15de20a82a4a0
4
+ data.tar.gz: 961c6ca2fd28da3fc86df5232c44fbf794f715abf5fa5a10d4707c7e3ddd3263
5
5
  SHA512:
6
- metadata.gz: 805a350eb86db74b7e807432cf4915d5eb081c7adc0b50de26a17eee9126be6b92d47e0461f12b83d393f5c8620ba196aa27458d093fc443e5cec13f536e7b23
7
- data.tar.gz: 39c06a31e6e590ed3e5d5a9ba11d955630852c9ba374ca8334e89ac09e3c416068ddf8ee4fd82495856b0812670a79f60e67ca279d5b149d557158a5f759f389
6
+ metadata.gz: 82f66c8fa2f5fe8ce4ee7036db43be7d47838cd9861365f84cd8851a062941c6611132f4ec50c6af1286b193d3273ee5633f3d09a431e2ac62306f02ac045105
7
+ data.tar.gz: 8817aab0b713c3e83e986713a9f43f5701138ffcf478fb2dc24f9083093d3f2039ce9de423b2b9b3ac5bc66dfd75e04dd453e11cafb9e8c9cc664b34cf9a258e
@@ -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
- # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
14
- # ruby: [2.5, 2.6, 2.7, '3.0', head, jruby, jruby-head, truffleruby, truffleruby-head]
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@v2
17
+ - uses: actions/checkout@v3
20
18
  - uses: ruby/setup-ruby@v1
21
19
  with:
22
20
  ruby-version: ${{ matrix.ruby }}
23
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
24
- - run: bundle exec rake
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.1
1
+ rails-7.0
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.7.2
1
+ ruby-3.2.2
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,184 +1,210 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relation (0.3.8)
5
- activerecord
4
+ relation (0.4.3)
6
5
 
7
6
  GEM
8
7
  remote: https://rubygems.org/
9
8
  specs:
10
- actioncable (6.1.3.2)
11
- actionpack (= 6.1.3.2)
12
- activesupport (= 6.1.3.2)
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 (6.1.3.2)
16
- actionpack (= 6.1.3.2)
17
- activejob (= 6.1.3.2)
18
- activerecord (= 6.1.3.2)
19
- activestorage (= 6.1.3.2)
20
- activesupport (= 6.1.3.2)
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
- actionmailer (6.1.3.2)
23
- actionpack (= 6.1.3.2)
24
- actionview (= 6.1.3.2)
25
- activejob (= 6.1.3.2)
26
- activesupport (= 6.1.3.2)
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 (6.1.3.2)
30
- actionview (= 6.1.3.2)
31
- activesupport (= 6.1.3.2)
32
- rack (~> 2.0, >= 2.0.9)
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 (6.1.3.2)
37
- actionpack (= 6.1.3.2)
38
- activerecord (= 6.1.3.2)
39
- activestorage (= 6.1.3.2)
40
- activesupport (= 6.1.3.2)
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 (6.1.3.2)
43
- activesupport (= 6.1.3.2)
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 (6.1.3.2)
49
- activesupport (= 6.1.3.2)
54
+ activejob (7.0.4.3)
55
+ activesupport (= 7.0.4.3)
50
56
  globalid (>= 0.3.6)
51
- activemodel (6.1.3.2)
52
- activesupport (= 6.1.3.2)
53
- activerecord (6.1.3.2)
54
- activemodel (= 6.1.3.2)
55
- activesupport (= 6.1.3.2)
56
- activestorage (6.1.3.2)
57
- actionpack (= 6.1.3.2)
58
- activejob (= 6.1.3.2)
59
- activerecord (= 6.1.3.2)
60
- activesupport (= 6.1.3.2)
61
- marcel (~> 1.0.0)
62
- mini_mime (~> 1.0.2)
63
- activesupport (6.1.3.2)
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
- concurrent-ruby (1.1.9)
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.10.0)
79
- globalid (0.4.2)
80
- activesupport (>= 4.2.0)
81
- i18n (1.8.10)
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
- loofah (2.10.0)
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.7.1)
94
+ mail (2.8.1)
87
95
  mini_mime (>= 0.1.1)
88
- marcel (1.0.1)
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.0.3)
91
- minitest (5.14.4)
92
- nio4r (2.5.7)
93
- nokogiri (1.11.7-x86_64-linux)
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.20.1)
97
- parser (3.0.1.1)
119
+ parallel (1.22.1)
120
+ parser (3.2.2.0)
98
121
  ast (~> 2.4.1)
99
- racc (1.5.2)
100
- rack (2.2.3)
101
- rack-test (1.1.0)
102
- rack (>= 1.0, < 3)
103
- rails (6.1.3.2)
104
- actioncable (= 6.1.3.2)
105
- actionmailbox (= 6.1.3.2)
106
- actionmailer (= 6.1.3.2)
107
- actionpack (= 6.1.3.2)
108
- actiontext (= 6.1.3.2)
109
- actionview (= 6.1.3.2)
110
- activejob (= 6.1.3.2)
111
- activemodel (= 6.1.3.2)
112
- activerecord (= 6.1.3.2)
113
- activestorage (= 6.1.3.2)
114
- activesupport (= 6.1.3.2)
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 (= 6.1.3.2)
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.3.0)
122
- loofah (~> 2.3)
123
- railties (6.1.3.2)
124
- actionpack (= 6.1.3.2)
125
- activesupport (= 6.1.3.2)
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 (>= 0.8.7)
149
+ rake (>= 12.2)
128
150
  thor (~> 1.0)
129
- rainbow (3.0.0)
130
- rake (13.0.3)
131
- regexp_parser (2.1.1)
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
- rubocop (1.17.0)
156
+ ricecream (0.2.1)
157
+ rubocop (1.48.1)
158
+ json (~> 2.3)
134
159
  parallel (~> 1.10)
135
- parser (>= 3.0.0.0)
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.7.0, < 2.0)
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 (>= 1.4.0, < 3.0)
142
- rubocop-ast (1.7.0)
143
- parser (>= 3.0.1.1)
144
- ruby-progressbar (1.11.0)
145
- simplecov (0.21.2)
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.3)
151
- sprockets (4.0.2)
152
- concurrent-ruby (~> 1.0)
153
- rack (> 1, < 3)
154
- sprockets-rails (3.2.2)
155
- actionpack (>= 4.0)
156
- activesupport (>= 4.0)
157
- sprockets (>= 3.0.0)
158
- sqlite3 (1.4.2)
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.0.0)
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.4.2)
192
+ zeitwerk (2.6.7)
167
193
 
168
194
  PLATFORMS
169
195
  x86_64-linux
170
196
 
171
197
  DEPENDENCIES
172
- appraisal
173
- bundler
198
+ combustion
174
199
  minitest
200
+ minitest-spec-rails
175
201
  observr
176
202
  rails
177
- rake
178
203
  relation!
179
- rubocop
204
+ ricecream
180
205
  simplecov
181
206
  sqlite3
207
+ standard
182
208
 
183
209
  BUNDLED WITH
184
- 2.2.17
210
+ 2.4.10
data/MIT-LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright 2015-2021 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
@@ -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, from:id, to_id).
8
- No additional column/field is required in a particular tables.
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
- $ [sudo] gem install relation
33
-
34
- or:
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/20150810152808_relation.rb"
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
- Relation.add order, user
54
- Relation.add order, user2
55
- Relation.add order2, user2
50
+ ``` ruby
51
+ Relation.add order, user
52
+ Relation.add order, user2
53
+ Relation.add order2, user2
56
54
 
57
- Relation.references order, User # -> [user, user2]
58
- Relation.references order2, User # -> [user2]
59
- Relation.followers Order, user # -> [order]
60
- 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]
61
59
 
62
- Relation.delete order2, user2
63
- Relation.followers Order, user2 # -> [order]
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
- 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)
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
- ## 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
@@ -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