adjustable_schema 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5514bed45ea4246eb3af8f2331cbc0d911aa3582fadd0cf6fb3ec6fbb61f9c00
4
- data.tar.gz: e042af98603878baa75b1f2a922157dd764572f568d3a836b73c509e654dd2d3
3
+ metadata.gz: 1fcf0b1a81ed7592a9a493a94e1f56f559c12d44fe3fd646b638b92d8de3e45c
4
+ data.tar.gz: 5fdefcce5b67338a94153e644da24e4003cbeb42563d27842685ff3aeaea8523
5
5
  SHA512:
6
- metadata.gz: e5d3a6f67b13c183c2728582df56f03337362b087e8486130758cdaacd87c72215dd74099a98be202d185b7a84c044d892469122f6850fadc81de6c3e98036a4
7
- data.tar.gz: 2e7113dd0df58bb104086316d4c883e3fe96c2e1eb3b96bb201567937a799edd16502c303fd05a091a83d8afb6e3481a4157a7d2402fc596a80abb01fe493866
6
+ metadata.gz: 02689cf5293142beee6a4e6589841a4e544fac26c6ec2d3aa589c7b9a3fa883a700a82e49968378132fdeef24ee42831fbae840d14b3868bea98de03cb111ce8
7
+ data.tar.gz: 65437d627f58a0dd0f4eb88213ff522dffda0dde20063b10e99e89ca75eef9aaf17fd1b7102114fd5d38fdfd9e8de8564185ca8fc7ff769581236157fe5634fc
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ## [0.12.0] — 2026-11-03
2
+
3
+ ### Changed
4
+
5
+ - Removed deprecated `Relationship.seed!`.
6
+
7
+ ### Added
8
+
9
+ - Checks for related records’ presence on roleless recursive associations:
10
+ - `.intermediate` —
11
+ records having only one child record associated;
12
+ - `.branching` —
13
+ records having several child records associated;
14
+ - `.with_next_level` helper scope.
15
+ - Rails 8.2 support.
16
+
17
+
18
+ ## [0.11.1] — 2025-05-19
19
+
20
+ ### Fixed
21
+
22
+ - Associations setup for inherited models got broken in v0.11.0.
23
+
24
+
1
25
  ## [0.11.0] — 2025-05-09
2
26
 
3
27
  ### Changed
data/README.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Adjustable Schema for Rails
2
2
 
3
+ ![GitHub Actions Workflow Status](
4
+ https://img.shields.io/github/actions/workflow/status/Alexander-Senko/adjustable_schema/ci.yml
5
+ )
6
+ [![Maintainability](
7
+ https://qlty.sh/gh/Alexander-Senko/projects/adjustable_schema/maintainability.svg
8
+ )](
9
+ https://qlty.sh/gh/Alexander-Senko/projects/adjustable_schema
10
+ )
11
+ [![Code Coverage](
12
+ https://qlty.sh/gh/Alexander-Senko/projects/adjustable_schema/coverage.svg
13
+ )](
14
+ https://qlty.sh/gh/Alexander-Senko/projects/adjustable_schema
15
+ )
16
+
3
17
  Define your model associations in the database without changing the schema or models.
4
18
 
5
19
  This Rails Engine was renamed and refactored from [Rails Dynamic Associations](https://github.com/Alexander-Senko/rails_dynamic_associations).
data/Rakefile CHANGED
@@ -5,6 +5,4 @@ require 'bundler/setup'
5
5
  APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
6
6
  load 'rails/tasks/engine.rake'
7
7
 
8
- load 'rails/tasks/statistics.rake'
9
-
10
8
  require 'bundler/gem_tasks'
@@ -98,15 +98,6 @@ module AdjustableSchema
98
98
  end
99
99
  .reduce &:or
100
100
  end
101
-
102
- def seed!(...)
103
- AdjustableSchema.deprecator.warn <<~TEXT.squish
104
- #{self}.#{__method__} is deprecated and will be removed in v0.12.
105
- Please use AdjustableSchema.relationship! instead.
106
- TEXT
107
-
108
- AdjustableSchema.relationship!(...)
109
- end
110
101
  end
111
102
 
112
103
  delegate :name, to: :role, allow_nil: true
@@ -1,12 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'memery'
4
+
3
5
  module AdjustableSchema
4
6
  module ActiveRecord # :nodoc:
5
7
  concern :Associations do
6
8
  class_methods do
7
- private
9
+ include Memery
10
+
11
+ protected
12
+
13
+ memoize def adjust_associations
14
+ adjust_parent_associations
8
15
 
9
- def adjust_associations
10
16
  relationships
11
17
  .flat_map do |direction, relationships|
12
18
  relationships
@@ -19,6 +25,24 @@ module AdjustableSchema
19
25
  &.tap do # finally, if any relationships have been set up
20
26
  include Relationships::InstanceMethods
21
27
  end
28
+ &.size # optimization
29
+ end
30
+
31
+ private
32
+
33
+ # Parent dynamic associations are not automatically inherited
34
+ # for an STI subclass if it defines its own associations.
35
+ #
36
+ # This method copies missing parent’s associations if any.
37
+ def adjust_parent_associations
38
+ return unless superclass < Associations
39
+
40
+ superclass.adjust_associations or
41
+ return # optimization
42
+
43
+ superclass._reflections
44
+ .except(*_reflections.keys)
45
+ .each { |name, reflection| add_reflection name, reflection }
22
46
  end
23
47
 
24
48
  def setup_association direction, target = self, role = nil
@@ -29,6 +53,10 @@ module AdjustableSchema
29
53
  def adjustable_association(...)
30
54
  Association.new(self, ...)
31
55
  end
56
+
57
+ def add_reflection(...)
58
+ ::ActiveRecord::Reflection.add_reflection(self, ...)
59
+ end
32
60
  end
33
61
  end
34
62
  end
@@ -11,9 +11,12 @@ module AdjustableSchema
11
11
  include Memery
12
12
 
13
13
  memoize def relationships
14
- Config.association_directions.index_with do
15
- Relationship.abstract.send Config.shortcuts.opposite[it], self
16
- end
14
+ Config.association_directions
15
+ .with_opposite
16
+ .transform_values do
17
+ Relationship.abstract
18
+ .where "#{it}_type": name
19
+ end
17
20
  end
18
21
 
19
22
  def roles(&) = Role.of self, &
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ case Rails.version
4
+ when ('8.2'...)
5
+ Arel::Table.prepend Module.new { # HACK: dual-API
6
+ def initialize(name = nil, **) = super(name:, **)
7
+ }
8
+ end
@@ -13,6 +13,10 @@ module AdjustableSchema
13
13
 
14
14
  name_for_any( target_name) => -> { where.associated name },
15
15
  name_for_none(target_name) => -> { where.missing name },
16
+ intermediate: -> { with_next_level.having('COUNT(*) = 1') },
17
+ branching: -> { with_next_level.having('COUNT(*) > 1') },
18
+
19
+ with_next_level: -> { joins(name).group arel_table[primary_key] },
16
20
  }
17
21
  end
18
22
 
@@ -19,6 +19,12 @@ module AdjustableSchema
19
19
 
20
20
  include Memery
21
21
 
22
+ class << self
23
+ include Memery
24
+
25
+ memoize :new # unique
26
+ end
27
+
22
28
  def initialize(...)
23
29
  super
24
30
 
@@ -33,7 +39,7 @@ module AdjustableSchema
33
39
  has_many name, **options do
34
40
  include Scopes
35
41
  include Scopes::Recursive if association.recursive?
36
- end
42
+ end or return
37
43
 
38
44
  define_scopes
39
45
  define_methods
@@ -1,25 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Gem::Author ||= Struct.new(
4
- :name,
5
- :email,
6
- :github,
7
- ) do
8
- def github_url = github && "https://github.com/#{github}"
3
+ begin
4
+ require 'rubygems/author'
5
+ rescue LoadError
6
+ require_relative '../../vendor/gems/rubygems-author/lib/rubygems/author'
9
7
  end
10
8
 
11
9
  module AdjustableSchema # :nodoc:
12
- AUTHORS = [ # rubocop:disable Style/MutableConstant
13
- Gem::Author.new(
14
- name: 'Alexander Senko',
15
- email: 'Alexander.Senko@gmail.com',
16
- github: 'Alexander-Senko',
17
- ),
18
- ]
19
-
20
- class << AUTHORS
21
- def names = filter_map &:name
22
- def emails = filter_map &:email
23
- def github_url = filter_map(&:github_url).first
10
+ class Author < Gem::Author # :nodoc:
11
+ new(
12
+ name: 'Alexander Senko',
13
+ email: 'Alexander.Senko@gmail.com',
14
+ github: 'Alexander-Senko',
15
+ )
24
16
  end
25
17
  end
@@ -34,6 +34,10 @@ module AdjustableSchema
34
34
  grep_v(to).sole
35
35
  end
36
36
 
37
+ def with_opposite
38
+ index_with { opposite to: it }
39
+ end
40
+
37
41
  private
38
42
 
39
43
  def config section = nil
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdjustableSchema
4
- VERSION = '0.11.0'
4
+ VERSION = '0.12.0'
5
5
  end
metadata CHANGED
@@ -1,128 +1,138 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adjustable_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
- - Alexander Senko
7
+ - Alexander Senko
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-08 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: rails
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - "~>"
17
- - !ruby/object:Gem::Version
18
- version: '8.0'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - "~>"
24
- - !ruby/object:Gem::Version
25
- version: '8.0'
26
- - !ruby/object:Gem::Dependency
27
- name: rails_model_load_hook
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '0.2'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '0.2'
40
- - !ruby/object:Gem::Dependency
41
- name: organizer-rails
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '0.2'
47
- type: :runtime
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '0.2'
54
- - !ruby/object:Gem::Dependency
55
- name: memery
56
- requirement: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
61
- type: :runtime
62
- prerelease: false
63
- version_requirements: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
- description: Rails Engine to allow ActiveRecord associations be set up in the DB instead
69
- of being hard-coded.
12
+ - !ruby/object:Gem::Dependency
13
+ name: rails
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: "8.0"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: "8.0"
28
+ - !ruby/object:Gem::Dependency
29
+ name: rails_model_load_hook
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ -
33
+ - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: "0.2"
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ -
41
+ - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: "0.2"
44
+ - !ruby/object:Gem::Dependency
45
+ name: organizer-rails
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ -
49
+ - ~>
50
+ - !ruby/object:Gem::Version
51
+ version: "0.2"
52
+ type: :runtime
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ -
57
+ - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: "0.2"
60
+ - !ruby/object:Gem::Dependency
61
+ name: memery
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ -
65
+ - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ -
73
+ - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ description: Rails Engine to allow ActiveRecord associations be set up in the DB instead of being hard-coded.
70
77
  email:
71
- - Alexander.Senko@gmail.com
78
+ - Alexander.Senko@gmail.com
72
79
  executables: []
73
80
  extensions: []
74
81
  extra_rdoc_files: []
75
82
  files:
76
- - CHANGELOG.md
77
- - MIT-LICENSE
78
- - README.md
79
- - Rakefile
80
- - app/models/adjustable_schema/application_record.rb
81
- - app/models/adjustable_schema/relationship.rb
82
- - app/models/adjustable_schema/relationship/role.rb
83
- - app/models/concerns/adjustable_schema/active_record/associations.rb
84
- - app/models/concerns/adjustable_schema/active_record/relationships.rb
85
- - app/models/concerns/adjustable_schema/active_record/relationships/builder.rb
86
- - app/models/concerns/adjustable_schema/actors.rb
87
- - config/initializers/associations.rb
88
- - config/initializers/model_names.rb
89
- - db/migrate/01_create_adjustable_schema_relationship_tables.rb
90
- - lib/adjustable_schema.rb
91
- - lib/adjustable_schema/active_record.rb
92
- - lib/adjustable_schema/active_record/association.rb
93
- - lib/adjustable_schema/active_record/association/hierarchy.rb
94
- - lib/adjustable_schema/active_record/association/naming.rb
95
- - lib/adjustable_schema/active_record/association/referenced.rb
96
- - lib/adjustable_schema/active_record/association/roleless.rb
97
- - lib/adjustable_schema/active_record/association/scopes.rb
98
- - lib/adjustable_schema/active_record/builder.rb
99
- - lib/adjustable_schema/authors.rb
100
- - lib/adjustable_schema/config.rb
101
- - lib/adjustable_schema/engine.rb
102
- - lib/adjustable_schema/version.rb
103
- - lib/tasks/adjustable_schema_tasks.rake
104
- homepage: https://github.com/Alexander-Senko/adjustable_schema
83
+ - CHANGELOG.md
84
+ - MIT-LICENSE
85
+ - README.md
86
+ - Rakefile
87
+ - app/models/adjustable_schema/application_record.rb
88
+ - app/models/adjustable_schema/relationship.rb
89
+ - app/models/adjustable_schema/relationship/role.rb
90
+ - app/models/concerns/adjustable_schema/active_record/associations.rb
91
+ - app/models/concerns/adjustable_schema/active_record/relationships.rb
92
+ - app/models/concerns/adjustable_schema/active_record/relationships/builder.rb
93
+ - app/models/concerns/adjustable_schema/actors.rb
94
+ - config/initializers/associations.rb
95
+ - config/initializers/compatibility.rb
96
+ - config/initializers/model_names.rb
97
+ - db/migrate/01_create_adjustable_schema_relationship_tables.rb
98
+ - lib/adjustable_schema.rb
99
+ - lib/adjustable_schema/active_record.rb
100
+ - lib/adjustable_schema/active_record/association.rb
101
+ - lib/adjustable_schema/active_record/association/hierarchy.rb
102
+ - lib/adjustable_schema/active_record/association/naming.rb
103
+ - lib/adjustable_schema/active_record/association/referenced.rb
104
+ - lib/adjustable_schema/active_record/association/roleless.rb
105
+ - lib/adjustable_schema/active_record/association/scopes.rb
106
+ - lib/adjustable_schema/active_record/builder.rb
107
+ - lib/adjustable_schema/authors.rb
108
+ - lib/adjustable_schema/config.rb
109
+ - lib/adjustable_schema/engine.rb
110
+ - lib/adjustable_schema/version.rb
111
+ - lib/tasks/adjustable_schema_tasks.rake
112
+ homepage: "https://github.com/Alexander-Senko/adjustable_schema"
105
113
  licenses:
106
- - MIT
114
+ - MIT
107
115
  metadata:
108
- homepage_uri: https://github.com/Alexander-Senko/adjustable_schema
109
- source_code_uri: https://github.com/Alexander-Senko/adjustable_schema
110
- changelog_uri: https://github.com/Alexander-Senko/adjustable_schema/blob/v0.11.0/CHANGELOG.md
116
+ homepage_uri: "https://github.com/Alexander-Senko/adjustable_schema"
117
+ source_code_uri: "https://github.com/Alexander-Senko/adjustable_schema"
118
+ changelog_uri: "https://github.com/Alexander-Senko/adjustable_schema/blob/v0.12.0/CHANGELOG.md"
111
119
  rdoc_options: []
112
120
  require_paths:
113
- - lib
121
+ - lib
114
122
  required_ruby_version: !ruby/object:Gem::Requirement
115
123
  requirements:
116
- - - ">="
117
- - !ruby/object:Gem::Version
118
- version: '3.4'
124
+ -
125
+ - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: "3.4"
119
128
  required_rubygems_version: !ruby/object:Gem::Requirement
120
129
  requirements:
121
- - - ">="
122
- - !ruby/object:Gem::Version
123
- version: '0'
130
+ -
131
+ - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: "0"
124
134
  requirements: []
125
- rubygems_version: 3.6.5
135
+ rubygems_version: 4.1.0.dev
126
136
  specification_version: 4
127
137
  summary: Adjustable data schemas for Rails
128
138
  test_files: []