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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b1390e4f564f54d0e8a840fae882bf7a494b51323846ab06e05a786c332fc37
4
- data.tar.gz: 5458b1a98b4b3a3dea0c3a8e2cd66e42003683cbbd4af95c939af8fe1810ce34
3
+ metadata.gz: 4525066ba26fd96f436d9e4620260becf28e8dade751b5caee3b56aa00791211
4
+ data.tar.gz: 7f3d844b8be42f563aaf20fcf5b0b1519efc7a9b7e465fb2e06231a57be68326
5
5
  SHA512:
6
- metadata.gz: dee15ab2468fca2b6bf3739df1b65508dd80ae87830833d27895e05a21c59392e3856ffbd78742cc0c067bfd1db66b364a880f0bf5401a3a3cc5cac2879ec59e
7
- data.tar.gz: 984449dfcba1f1797830b5153439d2873187b0fe32aaefe23cb21bab76b49f49906f70dc562eacb92653a531eb828c262449bf41a71b4507782de25ac38214d0
6
+ metadata.gz: 1bd658b2800d4d355057e5d17e032b1eee417dd5a74537cc24fb50dfd42a6785423a71c437e536ad2885ae5d0b78ce498aa9efe4f8367eace50b78f314d5cbd6
7
+ data.tar.gz: 263cdad0cf81bfb3b1a050ef98c78d4738019732b262aa23a08a759e8ef07e25e9110af092ad6ba54e28ad7356be7b64da103d4438b28822ed077529bc8be0a3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## [0.10.0] — 2025-04-23
2
+
3
+ ### Changed
4
+
5
+ - No more polymorphic STI associations tricks (see 0dd30220 for details).
6
+
7
+ ### Added
8
+
9
+ - Special naming rules for “actor-like” models.
10
+
11
+
1
12
  ## [0.9.0] — 2025-03-10
2
13
 
3
14
  ### Changed
data/README.md CHANGED
@@ -56,7 +56,7 @@ book.editor_people
56
56
 
57
57
  #### Special cases
58
58
 
59
- ##### "Actor-like" models
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AdjustableSchema # :nodoc:
4
+ concern :Actors do
5
+ class_methods do
6
+ def actor?
7
+ Config.actor_models.any? { self <= it }
8
+ end
9
+ end
10
+ end
11
+ 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
@@ -7,6 +7,7 @@ module AdjustableSchema
7
7
  ActiveSupport.on_load :active_record do
8
8
  include Associations
9
9
  include Relationships
10
+ include Actors
10
11
  end
11
12
  end
12
13
  end
@@ -3,15 +3,23 @@
3
3
  Gem::Author ||= Struct.new(
4
4
  :name,
5
5
  :email,
6
- :github_url,
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: 'Alexander Senko',
13
- email: 'Alexander.Senko@gmail.com',
14
- github_url: 'https://github.com/Alexander-Senko',
14
+ name: 'Alexander Senko',
15
+ email: 'Alexander.Senko@gmail.com',
16
+ github: 'Alexander-Senko',
15
17
  ),
16
- ].freeze
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
@@ -20,5 +20,9 @@ module AdjustableSchema
20
20
  },
21
21
  },
22
22
  }
23
+
24
+ config.actor_model_names = %w[
25
+ User
26
+ ]
23
27
  end
24
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AdjustableSchema
4
- VERSION = '0.9.0'
4
+ VERSION = '0.10.0'
5
5
  end
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.9.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-03-09 00:00:00.000000000 Z
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.9.0/CHANGELOG.md
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