adjustable_schema 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/01_create_adjustable_schema_relationship_tables.rb +11 -4
- data/lib/adjustable_schema/active_record/association/naming.rb +2 -2
- data/lib/adjustable_schema/active_record/association.rb +6 -4
- data/lib/adjustable_schema/engine.rb +3 -0
- data/lib/adjustable_schema/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a26450a562fbcde4b87abd3a84e85f577d3c1a7c9f8ecfdf22b79728875f1e6
|
4
|
+
data.tar.gz: b2cda5f212ae129a97b92a80440f8e053af2c44d5c54676e2358da3230cb987a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bf5d1bcef25e17cdbfc7de6d1f4f0278571169e9416d96fa4542ae654ea236184b39fa162938870d085a5afc496beac98e8a6a48ad311e69a277a97eb2f01d8
|
7
|
+
data.tar.gz: '099e2973293293635d6a1a1cda5a3105363e5c42dedc14cc30f07fc967870b6586da29dd4443e2ab37ee7b93059e063e538a8f3c39bc98308354342f5398a3bb'
|
@@ -4,7 +4,7 @@ class CreateAdjustableSchemaRelationshipTables < ActiveRecord::Migration[7.1]
|
|
4
4
|
primary_key_type, foreign_key_type = primary_and_foreign_key_types
|
5
5
|
|
6
6
|
create_table :adjustable_schema_relationship_roles do |t|
|
7
|
-
t.string :name, index: { unique: true }
|
7
|
+
t.string :name, null: false, index: { unique: true }
|
8
8
|
|
9
9
|
t.timestamps
|
10
10
|
end
|
@@ -17,13 +17,20 @@ class CreateAdjustableSchemaRelationshipTables < ActiveRecord::Migration[7.1]
|
|
17
17
|
|
18
18
|
t.timestamps
|
19
19
|
|
20
|
-
|
20
|
+
%i[
|
21
21
|
source_id source_type
|
22
22
|
target_id target_type
|
23
23
|
role_id
|
24
24
|
].tap { |columns|
|
25
|
-
|
26
|
-
|
25
|
+
columns.reject! { _1.ends_with? '_type' } if foreign_key_type == :uuid # OPTIMIZATION: IDs are unique
|
26
|
+
|
27
|
+
# NULLS are DISTINCT by default.
|
28
|
+
# One can use `ADD CONSTRAINT … UNIQUE NULLS NOT DISTINCT (…)` instead
|
29
|
+
t.index columns,
|
30
|
+
unique: true, where: 'role_id IS NOT NULL', name: :index_adjustable_schema_relationships_uniqueness_with_role
|
31
|
+
t.index columns.excluding(:role_id),
|
32
|
+
unique: true, where: 'role_id IS NULL', name: :index_adjustable_schema_relationships_uniqueness_without_role
|
33
|
+
}
|
27
34
|
end
|
28
35
|
end
|
29
36
|
|
@@ -38,7 +38,7 @@ module AdjustableSchema
|
|
38
38
|
private
|
39
39
|
|
40
40
|
memoize def name_with_role
|
41
|
-
if
|
41
|
+
if recursive?
|
42
42
|
{
|
43
43
|
source: role.name,
|
44
44
|
target: "#{role.name.passivize}_#{target_name}",
|
@@ -52,7 +52,7 @@ module AdjustableSchema
|
|
52
52
|
end
|
53
53
|
|
54
54
|
memoize def name_without_role
|
55
|
-
if
|
55
|
+
if recursive?
|
56
56
|
Config.association_directions
|
57
57
|
.self[direction]
|
58
58
|
else
|
@@ -15,22 +15,24 @@ module AdjustableSchema
|
|
15
15
|
class_name: target.name
|
16
16
|
}) do
|
17
17
|
include Scopes
|
18
|
-
include Scopes::Recursive if association.
|
18
|
+
include Scopes::Recursive if association.recursive?
|
19
19
|
end
|
20
20
|
|
21
21
|
define_scopes
|
22
22
|
define_methods
|
23
23
|
|
24
24
|
unless role
|
25
|
-
|
26
|
-
|
25
|
+
# HACK: using `try` to overcome a Rails bug
|
26
|
+
# (see https://github.com/rails/rails/issues/40109)
|
27
|
+
has_many target_name.tableize.to_sym, -> { try :roleless }, **options if
|
28
|
+
recursive?
|
27
29
|
|
28
30
|
define_role_methods
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
33
|
-
def
|
35
|
+
def recursive? = target == owner
|
34
36
|
|
35
37
|
private
|
36
38
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adjustable_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Senko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -111,7 +111,7 @@ licenses:
|
|
111
111
|
metadata:
|
112
112
|
homepage_uri: https://github.com/Alexander-Senko/adjustable_schema
|
113
113
|
source_code_uri: https://github.com/Alexander-Senko/adjustable_schema
|
114
|
-
changelog_uri: https://github.com/Alexander-Senko/adjustable_schema/blob/v0.7.
|
114
|
+
changelog_uri: https://github.com/Alexander-Senko/adjustable_schema/blob/v0.7.1/CHANGELOG.md
|
115
115
|
post_install_message:
|
116
116
|
rdoc_options: []
|
117
117
|
require_paths:
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
rubygems_version: 3.5.
|
130
|
+
rubygems_version: 3.5.6
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: Adjustable data schemas for Rails
|