adjustable_schema 0.9.0 → 0.10.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 +11 -0
- data/README.md +10 -1
- data/app/models/adjustable_schema/relationship.rb +0 -15
- data/app/models/concerns/adjustable_schema/actors.rb +11 -0
- data/lib/adjustable_schema/active_record/association/naming.rb +10 -0
- data/lib/adjustable_schema/active_record.rb +1 -0
- data/lib/adjustable_schema/authors.rb +16 -8
- data/lib/adjustable_schema/config.rb +5 -0
- data/lib/adjustable_schema/engine.rb +4 -0
- data/lib/adjustable_schema/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4525066ba26fd96f436d9e4620260becf28e8dade751b5caee3b56aa00791211
|
4
|
+
data.tar.gz: 7f3d844b8be42f563aaf20fcf5b0b1519efc7a9b7e465fb2e06231a57be68326
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bd658b2800d4d355057e5d17e032b1eee417dd5a74537cc24fb50dfd42a6785423a71c437e536ad2885ae5d0b78ce498aa9efe4f8367eace50b78f314d5cbd6
|
7
|
+
data.tar.gz: 263cdad0cf81bfb3b1a050ef98c78d4738019732b262aa23a08a759e8ef07e25e9110af092ad6ba54e28ad7356be7b64da103d4438b28822ed077529bc8be0a3
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -56,7 +56,7 @@ book.editor_people
|
|
56
56
|
|
57
57
|
#### Special cases
|
58
58
|
|
59
|
-
#####
|
59
|
+
##### “Actor-like” models
|
60
60
|
|
61
61
|
In case you have set up relationships with `User` model you'll get a slightly different naming:
|
62
62
|
|
@@ -73,6 +73,15 @@ book.editors
|
|
73
73
|
The list of models to be handled this way can be set with `actor_model_names` configuration parameter.
|
74
74
|
It includes `User` by default.
|
75
75
|
|
76
|
+
``` ruby
|
77
|
+
AdjustableSchema::Engine.configure do
|
78
|
+
config.actor_model_names << 'Person'
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
82
|
+
> [!CAUTION]
|
83
|
+
> Names are passed instead of model classes not to mess the loading up.
|
84
|
+
|
76
85
|
##### Self-referencing models
|
77
86
|
|
78
87
|
You may want to set up recursive relationships:
|
@@ -131,20 +131,5 @@ module AdjustableSchema
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def abstract? = not (source or target)
|
134
|
-
|
135
|
-
# HACK
|
136
|
-
# Using polymorphic associations in combination with single table inheritance (STI) is
|
137
|
-
# a little tricky. In order for the associations to work as expected, ensure that you
|
138
|
-
# store the base model for the STI models in the type column of the polymorphic
|
139
|
-
# association.
|
140
|
-
# https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Polymorphic+Associations
|
141
|
-
reflections
|
142
|
-
.values
|
143
|
-
.select { it.options[:polymorphic] }
|
144
|
-
.each do |reflection|
|
145
|
-
define_method "#{reflection.name}_type=" do |type|
|
146
|
-
super type && type.to_s.classify.constantize.base_class.to_s
|
147
|
-
end
|
148
|
-
end
|
149
134
|
end
|
150
135
|
end
|
@@ -37,10 +37,20 @@ module AdjustableSchema
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
module Actors # :nodoc:
|
41
|
+
include Memery
|
42
|
+
|
43
|
+
memoize def name_with_role = {
|
44
|
+
source: role.name,
|
45
|
+
target: "#{role.name.passivize}_#{target_name}",
|
46
|
+
}[direction]
|
47
|
+
end
|
48
|
+
|
40
49
|
def initialize(...)
|
41
50
|
super
|
42
51
|
|
43
52
|
extend Recursive if recursive?
|
53
|
+
extend Actors if target.actor?
|
44
54
|
end
|
45
55
|
|
46
56
|
memoize def name name = object_name
|
@@ -3,15 +3,23 @@
|
|
3
3
|
Gem::Author ||= Struct.new(
|
4
4
|
:name,
|
5
5
|
:email,
|
6
|
-
:
|
7
|
-
)
|
6
|
+
:github,
|
7
|
+
) do
|
8
|
+
def github_url = github && "https://github.com/#{github}"
|
9
|
+
end
|
8
10
|
|
9
|
-
module AdjustableSchema
|
10
|
-
AUTHORS = [
|
11
|
+
module AdjustableSchema # :nodoc:
|
12
|
+
AUTHORS = [ # rubocop:disable Style/MutableConstant
|
11
13
|
Gem::Author.new(
|
12
|
-
name:
|
13
|
-
email:
|
14
|
-
|
14
|
+
name: 'Alexander Senko',
|
15
|
+
email: 'Alexander.Senko@gmail.com',
|
16
|
+
github: 'Alexander-Senko',
|
15
17
|
),
|
16
|
-
]
|
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
|
24
|
+
end
|
17
25
|
end
|
@@ -66,6 +66,11 @@ module AdjustableSchema
|
|
66
66
|
module_function method
|
67
67
|
end
|
68
68
|
|
69
|
+
memoize def actor_models
|
70
|
+
Engine.config.actor_model_names
|
71
|
+
.filter_map &:safe_constantize
|
72
|
+
end
|
73
|
+
|
69
74
|
def association_names = Engine.config.names[:associations]
|
70
75
|
|
71
76
|
def normalize **options
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adjustable_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Senko
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-23 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rails
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- app/models/adjustable_schema/relationship/role.rb
|
83
83
|
- app/models/concerns/adjustable_schema/active_record/associations.rb
|
84
84
|
- app/models/concerns/adjustable_schema/active_record/relationships.rb
|
85
|
+
- app/models/concerns/adjustable_schema/actors.rb
|
85
86
|
- config/initializers/associations.rb
|
86
87
|
- config/initializers/model_names.rb
|
87
88
|
- db/migrate/01_create_adjustable_schema_relationship_tables.rb
|
@@ -103,7 +104,7 @@ licenses:
|
|
103
104
|
metadata:
|
104
105
|
homepage_uri: https://github.com/Alexander-Senko/adjustable_schema
|
105
106
|
source_code_uri: https://github.com/Alexander-Senko/adjustable_schema
|
106
|
-
changelog_uri: https://github.com/Alexander-Senko/adjustable_schema/blob/v0.
|
107
|
+
changelog_uri: https://github.com/Alexander-Senko/adjustable_schema/blob/v0.10.0/CHANGELOG.md
|
107
108
|
rdoc_options: []
|
108
109
|
require_paths:
|
109
110
|
- lib
|