active_record_compose 0.6.0 → 0.6.2
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/.rubocop.yml +6 -0
- data/CHANGELOG.md +13 -0
- data/README.md +1 -1
- data/lib/active_record_compose/delegate_attribute.rb +5 -10
- data/lib/active_record_compose/inner_model.rb +0 -2
- data/lib/active_record_compose/inner_model_collection.rb +3 -5
- data/lib/active_record_compose/model.rb +3 -3
- data/lib/active_record_compose/version.rb +1 -1
- data/sig/_internal/package_private.rbs +82 -0
- data/sig/active_record_compose.rbs +9 -55
- metadata +5 -8
- data/.rspec +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88e574f327847973e3b931ee6663de0d395fa6ff26de5830f92ac21d1445fe20
|
4
|
+
data.tar.gz: bb50aa19e200f15c3b16d6b7fe65dc4e94afc7e44eec3c94ef37ab18fc610b88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77a492aea1e8c5aec20bea84dbbd242c2f94d9d5674a705cacea4ad4b8b3991b54630009fb78ed425a6dee5f10d28dd5f473b7b581a92711701de07472d7a88f
|
7
|
+
data.tar.gz: a8386a77e58cb7db6c2478137af7bf24e606448987009257b151c695b746be9818de2d963b65672cc60e23b9a8dc7d0b29790087ea3a8271152c0115d2212bdf
|
data/.rubocop.yml
CHANGED
@@ -9,6 +9,9 @@ Style/ArgumentsForwarding:
|
|
9
9
|
Style/CommentedKeyword:
|
10
10
|
Enabled: false
|
11
11
|
|
12
|
+
Style/ClassAndModuleChildren:
|
13
|
+
Enabled: false
|
14
|
+
|
12
15
|
Style/Documentation:
|
13
16
|
Enabled: false
|
14
17
|
|
@@ -51,6 +54,9 @@ Metrics/AbcSize:
|
|
51
54
|
Metrics/BlockLength:
|
52
55
|
Enabled: false
|
53
56
|
|
57
|
+
Metrics/ClassLength:
|
58
|
+
Enabled: false
|
59
|
+
|
54
60
|
Metrics/MethodLength:
|
55
61
|
Enabled: false
|
56
62
|
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.6.2] - 2025-01-04
|
4
|
+
|
5
|
+
- fix: `delegate_attribute` defined in a subclass had an unintended side effect on the superclass.
|
6
|
+
- support ruby 3.4.x
|
7
|
+
- refactor: remove some `steep:ignore` by private rbs.
|
8
|
+
- refactor: place definitions that you don't want to be used much in private rbs.
|
9
|
+
- make `DelegateAttribute` dependent on `ActiveModel::Attributes` since it will not change in practice.
|
10
|
+
|
11
|
+
## [0.6.1] - 2024-12-23
|
12
|
+
|
13
|
+
- refactor: reorganize the overall structure of the test. Change from rspec to minitest
|
14
|
+
- ci: fix CI for rails new version.
|
15
|
+
|
3
16
|
## [0.6.0] - 2024-11-11
|
4
17
|
|
5
18
|
- refactor: limit the scope of methods needed only for internal library purposes.
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ If the callbacks are written in a class that inherits from `ActiveRecordCompose:
|
|
37
37
|
class AccountRegistration < ActiveRecordCompose::Model
|
38
38
|
def initialize(account = Account.new, attributes = {})
|
39
39
|
@account = account
|
40
|
-
super(attributes)
|
40
|
+
super(attributes) # When overrides `#initialize`, be sure to call `super`.
|
41
41
|
|
42
42
|
# By including AR instance in models, AR instance itself is saved when this model is saved.
|
43
43
|
models.push(account)
|
@@ -38,7 +38,8 @@ module ActiveRecordCompose
|
|
38
38
|
extend ActiveSupport::Concern
|
39
39
|
|
40
40
|
included do
|
41
|
-
|
41
|
+
# @type self: Class
|
42
|
+
class_attribute :delegated_attributes, instance_writer: false
|
42
43
|
end
|
43
44
|
|
44
45
|
module ClassMethods
|
@@ -52,9 +53,8 @@ module ActiveRecordCompose
|
|
52
53
|
[reader, writer]
|
53
54
|
end
|
54
55
|
|
55
|
-
delegate(*delegates, to:, allow_nil:, private:)
|
56
|
-
delegated_attributes =
|
57
|
-
attributes.each { delegated_attributes.push(_1.to_s) }
|
56
|
+
delegate(*delegates, to:, allow_nil:, private:)
|
57
|
+
self.delegated_attributes = delegated_attributes.to_a + attributes.map { _1.to_s }
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
@@ -63,12 +63,7 @@ module ActiveRecordCompose
|
|
63
63
|
#
|
64
64
|
# @return [Hash] hash with the attribute name as key and the attribute value as value.
|
65
65
|
def attributes
|
66
|
-
|
67
|
-
delegates = delegated_attributes # steep:ignore
|
68
|
-
|
69
|
-
# @type var attrs: Hash[String, untyped]
|
70
|
-
# @type var delegates: Array[String]
|
71
|
-
attrs.merge(delegates.to_h { [_1, public_send(_1)] })
|
66
|
+
super.merge(delegated_attributes.to_h { [_1, public_send(_1)] })
|
72
67
|
end
|
73
68
|
end
|
74
69
|
end
|
@@ -93,7 +93,6 @@ module ActiveRecordCompose
|
|
93
93
|
attr_reader :destroy_context_type, :if_option
|
94
94
|
|
95
95
|
# @private
|
96
|
-
# steep:ignore:start
|
97
96
|
module PackagePrivate
|
98
97
|
refine InnerModel do
|
99
98
|
# @private
|
@@ -104,6 +103,5 @@ module ActiveRecordCompose
|
|
104
103
|
def __raw_model = model
|
105
104
|
end
|
106
105
|
end
|
107
|
-
# steep:ignore:end
|
108
106
|
end
|
109
107
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'active_record_compose/inner_model'
|
4
4
|
|
5
5
|
module ActiveRecordCompose
|
6
|
-
using InnerModel::PackagePrivate
|
6
|
+
using InnerModel::PackagePrivate
|
7
7
|
|
8
8
|
class InnerModelCollection
|
9
9
|
include Enumerable
|
@@ -21,7 +21,7 @@ module ActiveRecordCompose
|
|
21
21
|
def each
|
22
22
|
return enum_for(:each) unless block_given?
|
23
23
|
|
24
|
-
models.each { yield _1.__raw_model }
|
24
|
+
models.each { yield _1.__raw_model }
|
25
25
|
self
|
26
26
|
end
|
27
27
|
|
@@ -79,7 +79,7 @@ module ActiveRecordCompose
|
|
79
79
|
attr_reader :owner, :models
|
80
80
|
|
81
81
|
def wrap(model, destroy: false, if: nil)
|
82
|
-
if model.is_a?(ActiveRecordCompose::InnerModel)
|
82
|
+
if model.is_a?(ActiveRecordCompose::InnerModel)
|
83
83
|
# @type var model: ActiveRecordCompose::InnerModel
|
84
84
|
model
|
85
85
|
else
|
@@ -97,7 +97,6 @@ module ActiveRecordCompose
|
|
97
97
|
end
|
98
98
|
|
99
99
|
# @private
|
100
|
-
# steep:ignore:start
|
101
100
|
module PackagePrivate
|
102
101
|
refine InnerModelCollection do
|
103
102
|
# Returns array of wrapped model instance.
|
@@ -107,6 +106,5 @@ module ActiveRecordCompose
|
|
107
106
|
def __wrapped_models = models.reject { _1.ignore? }.select { _1.__raw_model }
|
108
107
|
end
|
109
108
|
end
|
110
|
-
# steep:ignore:end
|
111
109
|
end
|
112
110
|
end
|
@@ -5,7 +5,7 @@ require 'active_record_compose/inner_model_collection'
|
|
5
5
|
require 'active_record_compose/transaction_support'
|
6
6
|
|
7
7
|
module ActiveRecordCompose
|
8
|
-
using InnerModelCollection::PackagePrivate
|
8
|
+
using InnerModelCollection::PackagePrivate
|
9
9
|
|
10
10
|
class Model
|
11
11
|
include ActiveModel::Model
|
@@ -153,12 +153,12 @@ module ActiveRecordCompose
|
|
153
153
|
def models = @__models ||= ActiveRecordCompose::InnerModelCollection.new(self)
|
154
154
|
|
155
155
|
def validate_models
|
156
|
-
wms = models.__wrapped_models
|
156
|
+
wms = models.__wrapped_models
|
157
157
|
wms.select { _1.invalid? }.each { errors.merge!(_1) }
|
158
158
|
end
|
159
159
|
|
160
160
|
def save_models(bang:)
|
161
|
-
wms = models.__wrapped_models
|
161
|
+
wms = models.__wrapped_models
|
162
162
|
wms.all? { bang ? _1.save! : _1.save }
|
163
163
|
end
|
164
164
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module ActiveRecordCompose
|
2
|
+
module DelegateAttribute : ActiveModel::Attributes
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
def attributes: -> Hash[String, untyped]
|
6
|
+
def delegated_attributes: () -> Array[String]
|
7
|
+
|
8
|
+
module ClassMethods : Module
|
9
|
+
def delegate_attribute: (*untyped methods, to: untyped, ?allow_nil: untyped?, ?private: untyped?) -> untyped
|
10
|
+
def delegated_attributes: () -> Array[String]
|
11
|
+
def delegated_attributes=: (Array[String]) -> untyped
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class InnerModelCollection
|
16
|
+
def initialize: (Model) -> void
|
17
|
+
|
18
|
+
private
|
19
|
+
attr_reader owner: Model
|
20
|
+
attr_reader models: Array[InnerModel]
|
21
|
+
def wrap: (_ARLike | InnerModel, ?destroy: (bool | Symbol | destroy_context_type), ?if: (nil | Symbol | condition_type)) -> InnerModel
|
22
|
+
|
23
|
+
module PackagePrivate
|
24
|
+
def __wrapped_models: () -> Array[InnerModel]
|
25
|
+
|
26
|
+
private
|
27
|
+
def models: () -> Array[InnerModel]
|
28
|
+
end
|
29
|
+
|
30
|
+
include PackagePrivate
|
31
|
+
end
|
32
|
+
|
33
|
+
class InnerModel
|
34
|
+
def initialize: (_ARLike, ?destroy: (bool | destroy_context_type), ?if: (nil | condition_type)) -> void
|
35
|
+
def destroy_context?: -> bool
|
36
|
+
def ignore?: -> bool
|
37
|
+
def save: -> bool
|
38
|
+
def save!: -> untyped
|
39
|
+
def invalid?: -> bool
|
40
|
+
def valid?: -> bool
|
41
|
+
def is_a?: (untyped) -> bool
|
42
|
+
def ==: (untyped) -> bool
|
43
|
+
|
44
|
+
private
|
45
|
+
attr_reader model: _ARLike
|
46
|
+
attr_reader destroy_context_type: (bool | destroy_context_type)
|
47
|
+
attr_reader if_option: (nil | condition_type)
|
48
|
+
|
49
|
+
module PackagePrivate
|
50
|
+
def __raw_model: () -> _ARLike
|
51
|
+
|
52
|
+
private
|
53
|
+
def model: () -> _ARLike
|
54
|
+
end
|
55
|
+
|
56
|
+
include PackagePrivate
|
57
|
+
end
|
58
|
+
|
59
|
+
class Model
|
60
|
+
include DelegateAttribute
|
61
|
+
extend DelegateAttribute::ClassMethods
|
62
|
+
include TransactionSupport
|
63
|
+
extend TransactionSupport::ClassMethods
|
64
|
+
|
65
|
+
@__models: InnerModelCollection
|
66
|
+
end
|
67
|
+
|
68
|
+
module TransactionSupport
|
69
|
+
include ActiveRecord::Transactions
|
70
|
+
|
71
|
+
def id: -> untyped
|
72
|
+
|
73
|
+
module ClassMethods
|
74
|
+
def connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
|
75
|
+
def lease_connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
|
76
|
+
def with_connection: [T] () { () -> T } -> T
|
77
|
+
|
78
|
+
private
|
79
|
+
def ar_class: -> singleton(ActiveRecord::Base)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -12,54 +12,23 @@ module ActiveRecordCompose
|
|
12
12
|
def invalid?: -> bool
|
13
13
|
def valid?: -> bool
|
14
14
|
def errors: -> untyped
|
15
|
+
def is_a?: (untyped) -> bool
|
15
16
|
def ==: (untyped) -> bool
|
16
17
|
end
|
17
18
|
|
18
19
|
type attribute_name = (String | Symbol)
|
19
|
-
type destroy_context_type = (
|
20
|
+
type destroy_context_type = ((^() -> boolish) | (^(_ARLike) -> boolish))
|
20
21
|
type condition_type = ((^() -> boolish) | (^(_ARLike) -> boolish))
|
21
22
|
|
22
|
-
module DelegateAttribute
|
23
|
-
extend ActiveSupport::Concern
|
24
|
-
|
25
|
-
def attributes: -> Hash[String, untyped]
|
26
|
-
|
27
|
-
module ClassMethods
|
28
|
-
def delegate_attribute: (*untyped methods, to: untyped?, ?allow_nil: untyped?, ?private: untyped?) -> untyped
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
23
|
class InnerModelCollection
|
33
24
|
include ::Enumerable[_ARLike]
|
34
25
|
|
35
|
-
def initialize: (Model) -> void
|
36
26
|
def each: () { (_ARLike) -> void } -> InnerModelCollection | () -> Enumerator[_ARLike, self]
|
37
27
|
def <<: (_ARLike) -> self
|
38
|
-
def push: (_ARLike, ?destroy: destroy_context_type, ?if: (nil | Symbol | condition_type)) -> self
|
28
|
+
def push: (_ARLike, ?destroy: (bool | Symbol | destroy_context_type), ?if: (nil | Symbol | condition_type)) -> self
|
39
29
|
def empty?: -> bool
|
40
30
|
def clear: -> self
|
41
|
-
def delete: (_ARLike
|
42
|
-
|
43
|
-
private
|
44
|
-
attr_reader owner: Model
|
45
|
-
attr_reader models: Array[InnerModel]
|
46
|
-
def wrap: (_ARLike | InnerModel, ?destroy: destroy_context_type, ?if: (nil | Symbol | condition_type)) -> InnerModel
|
47
|
-
end
|
48
|
-
|
49
|
-
class InnerModel
|
50
|
-
def initialize: (_ARLike, ?destroy: destroy_context_type, ?if: (nil | condition_type)) -> void
|
51
|
-
def destroy_context?: -> bool
|
52
|
-
def ignore?: -> bool
|
53
|
-
def save: -> bool
|
54
|
-
def save!: -> untyped
|
55
|
-
def invalid?: -> bool
|
56
|
-
def valid?: -> bool
|
57
|
-
def ==: (untyped) -> bool
|
58
|
-
|
59
|
-
private
|
60
|
-
attr_reader model: _ARLike
|
61
|
-
attr_reader destroy_context_type: destroy_context_type
|
62
|
-
attr_reader if_option: (nil | condition_type)
|
31
|
+
def delete: (_ARLike) -> InnerModelCollection?
|
63
32
|
end
|
64
33
|
|
65
34
|
class Model
|
@@ -68,12 +37,11 @@ module ActiveRecordCompose
|
|
68
37
|
include ActiveModel::Validations::Callbacks
|
69
38
|
extend ActiveModel::Validations::ClassMethods
|
70
39
|
include ActiveModel::Attributes
|
71
|
-
include DelegateAttribute
|
72
|
-
extend DelegateAttribute::ClassMethods
|
73
|
-
include TransactionSupport
|
74
|
-
extend TransactionSupport::ClassMethods
|
75
40
|
|
76
|
-
|
41
|
+
def self.delegate_attribute: (*untyped methods, to: untyped, ?allow_nil: untyped?, ?private: untyped?) -> untyped
|
42
|
+
def self.connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
|
43
|
+
def self.lease_connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
|
44
|
+
def self.with_connection: [T] () { () -> T } -> T
|
77
45
|
|
78
46
|
def initialize: (?Hash[attribute_name, untyped]) -> void
|
79
47
|
def save: -> bool
|
@@ -82,6 +50,7 @@ module ActiveRecordCompose
|
|
82
50
|
def create!: (?Hash[attribute_name, untyped]) -> untyped
|
83
51
|
def update: (?Hash[attribute_name, untyped]) -> bool
|
84
52
|
def update!: (?Hash[attribute_name, untyped]) -> untyped
|
53
|
+
def id: -> untyped
|
85
54
|
|
86
55
|
private
|
87
56
|
def models: -> InnerModelCollection
|
@@ -91,19 +60,4 @@ module ActiveRecordCompose
|
|
91
60
|
def raise_on_save_error: -> bot
|
92
61
|
def raise_on_save_error_message: -> String
|
93
62
|
end
|
94
|
-
|
95
|
-
module TransactionSupport
|
96
|
-
include ActiveRecord::Transactions
|
97
|
-
|
98
|
-
def id: -> untyped
|
99
|
-
|
100
|
-
module ClassMethods
|
101
|
-
def connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
|
102
|
-
def lease_connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
|
103
|
-
def with_connection: [T] () { () -> T } -> T
|
104
|
-
|
105
|
-
private
|
106
|
-
def ar_class: -> singleton(ActiveRecord::Base)
|
107
|
-
end
|
108
|
-
end
|
109
63
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_compose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hamajyotan
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-04 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activerecord
|
@@ -31,7 +30,6 @@ executables: []
|
|
31
30
|
extensions: []
|
32
31
|
extra_rdoc_files: []
|
33
32
|
files:
|
34
|
-
- ".rspec"
|
35
33
|
- ".rubocop.yml"
|
36
34
|
- CHANGELOG.md
|
37
35
|
- CODE_OF_CONDUCT.md
|
@@ -44,6 +42,7 @@ files:
|
|
44
42
|
- lib/active_record_compose/model.rb
|
45
43
|
- lib/active_record_compose/transaction_support.rb
|
46
44
|
- lib/active_record_compose/version.rb
|
45
|
+
- sig/_internal/package_private.rbs
|
47
46
|
- sig/active_record_compose.rbs
|
48
47
|
homepage: https://github.com/hamajyotan/active_record_compose
|
49
48
|
licenses:
|
@@ -52,9 +51,8 @@ metadata:
|
|
52
51
|
homepage_uri: https://github.com/hamajyotan/active_record_compose
|
53
52
|
source_code_uri: https://github.com/hamajyotan/active_record_compose
|
54
53
|
changelog_uri: https://github.com/hamajyotan/active_record_compose/blob/main/CHANGELOG.md
|
55
|
-
documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.6.
|
54
|
+
documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.6.2
|
56
55
|
rubygems_mfa_required: 'true'
|
57
|
-
post_install_message:
|
58
56
|
rdoc_options: []
|
59
57
|
require_paths:
|
60
58
|
- lib
|
@@ -69,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
67
|
- !ruby/object:Gem::Version
|
70
68
|
version: '0'
|
71
69
|
requirements: []
|
72
|
-
rubygems_version: 3.
|
73
|
-
signing_key:
|
70
|
+
rubygems_version: 3.6.2
|
74
71
|
specification_version: 4
|
75
72
|
summary: activemodel form object pattern
|
76
73
|
test_files: []
|
data/.rspec
DELETED