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 +4 -4
- data/CHANGELOG.md +24 -0
- data/README.md +14 -0
- data/Rakefile +0 -2
- data/app/models/adjustable_schema/relationship.rb +0 -9
- data/app/models/concerns/adjustable_schema/active_record/associations.rb +30 -2
- data/app/models/concerns/adjustable_schema/active_record/relationships.rb +6 -3
- data/config/initializers/compatibility.rb +8 -0
- data/lib/adjustable_schema/active_record/association/hierarchy.rb +4 -0
- data/lib/adjustable_schema/active_record/association.rb +7 -1
- data/lib/adjustable_schema/authors.rb +10 -18
- data/lib/adjustable_schema/config.rb +4 -0
- data/lib/adjustable_schema/version.rb +1 -1
- metadata +113 -103
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1fcf0b1a81ed7592a9a493a94e1f56f559c12d44fe3fd646b638b92d8de3e45c
|
|
4
|
+
data.tar.gz: 5fdefcce5b67338a94153e644da24e4003cbeb42563d27842685ff3aeaea8523
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
+

|
|
6
|
+
[](
|
|
9
|
+
https://qlty.sh/gh/Alexander-Senko/projects/adjustable_schema
|
|
10
|
+
)
|
|
11
|
+
[](
|
|
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
|
@@ -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
|
-
|
|
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
|
|
15
|
-
|
|
16
|
-
|
|
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, &
|
|
@@ -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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
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.
|
|
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:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
-
- !ruby/object:Gem::Dependency
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- !ruby/object:Gem::
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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/
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
- lib/adjustable_schema
|
|
92
|
-
- lib/adjustable_schema/active_record
|
|
93
|
-
- lib/adjustable_schema/active_record/association
|
|
94
|
-
- lib/adjustable_schema/active_record/association/
|
|
95
|
-
- lib/adjustable_schema/active_record/association/
|
|
96
|
-
- lib/adjustable_schema/active_record/association/
|
|
97
|
-
- lib/adjustable_schema/active_record/association/
|
|
98
|
-
- lib/adjustable_schema/active_record/
|
|
99
|
-
- lib/adjustable_schema/
|
|
100
|
-
- lib/adjustable_schema/
|
|
101
|
-
- lib/adjustable_schema/
|
|
102
|
-
- lib/adjustable_schema/
|
|
103
|
-
- lib/
|
|
104
|
-
|
|
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.
|
|
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
|
-
|
|
118
|
-
|
|
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
|
-
|
|
123
|
-
|
|
130
|
+
-
|
|
131
|
+
- ">="
|
|
132
|
+
- !ruby/object:Gem::Version
|
|
133
|
+
version: "0"
|
|
124
134
|
requirements: []
|
|
125
|
-
rubygems_version:
|
|
135
|
+
rubygems_version: 4.1.0.dev
|
|
126
136
|
specification_version: 4
|
|
127
137
|
summary: Adjustable data schemas for Rails
|
|
128
138
|
test_files: []
|