adjustable_schema 0.7.0 → 0.7.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: 8f905a89a0f7ab6c7c5c1f1feaa92a8fdb90f5e58003b164fed5ac55096fa258
4
- data.tar.gz: cf1c34dd8cce3497e64635ab1c59f079e257961979e55e9d31b30ae1aefeb4ff
3
+ metadata.gz: f44c8a85801250e7f4d0e26af1984a77f7e59d0d0f31f416e8d55343fdefb94a
4
+ data.tar.gz: fd68da65c3953097520bd12263924482d11330b7862c5bb7cf4aeffef972ecc8
5
5
  SHA512:
6
- metadata.gz: 892d3cc2cdfa8d6cd7d2405289e1417a54be8c8767fefa557208a2d7880d346e4c362adc1a5dc911d2091be1b172a15f88e3060c0c06b29b135a61efb773f5bb
7
- data.tar.gz: 145e68868903178eb0a6a82ed224912f657cdb7004f91df9cf70bec4c9c32241b1cd216515ee913369e6914f865007214d1a7aad5b5604664b73408974f5a323
6
+ metadata.gz: 05bc3d492e1794d4549668cf853b07fc824b5285fb6062287f11875ba8d408f1f2c1fc9fcaa26becd797ee04e9ed1c9ed997a4a998eb21dc70ba77486a1725e3
7
+ data.tar.gz: 44e8c6b9fef8f06d4bedd14213ae08a62e425825fe3a30c6843117c1d1b2e4cabbd66ec00e2bef5b5fb9ab1bd7e4e3696e3e784b24a62832bab66ee2d54d6b4b
@@ -5,8 +5,7 @@ module AdjustableSchema
5
5
  belongs_to :role, optional: true
6
6
 
7
7
  default_scope do
8
- references(:role)
9
- .includes :role
8
+ includes :role
10
9
  end
11
10
 
12
11
  Config.shortcuts.each &-> ((association, method)) do
@@ -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
- t.index %i[
20
+ %i[
21
21
  source_id source_type
22
22
  target_id target_type
23
23
  role_id
24
24
  ].tap { |columns|
25
- columns.reject! { _1.ends_with? '_type' } if foreign_key_type == :uuid # OPTIMIZATION: IDs are unique
26
- }, unique: true, name: :index_adjustable_schema_relationships_uniqueness
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 loop?
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 loop?
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.loop?
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
- has_many target_name.tableize.to_sym, -> { roleless }, **options if
26
- loop?
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 loop? = target == owner
35
+ def recursive? = target == owner
34
36
 
35
37
  private
36
38
 
@@ -1,3 +1,3 @@
1
1
  module AdjustableSchema
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.2'
3
3
  end
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.0
4
+ version: 0.7.2
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-02-25 00:00:00.000000000 Z
11
+ date: 2024-04-02 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.0/CHANGELOG.md
114
+ changelog_uri: https://github.com/Alexander-Senko/adjustable_schema/blob/v0.7.2/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.5
130
+ rubygems_version: 3.5.6
131
131
  signing_key:
132
132
  specification_version: 4
133
133
  summary: Adjustable data schemas for Rails