active_record_compose 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -0
- data/CHANGELOG.md +6 -0
- data/lib/active_record_compose/delegate_attribute.rb +13 -15
- data/lib/active_record_compose/inner_model.rb +14 -3
- data/lib/active_record_compose/inner_model_collection.rb +5 -3
- data/lib/active_record_compose/model.rb +2 -2
- data/lib/active_record_compose/transaction_support.rb +10 -4
- data/lib/active_record_compose/version.rb +1 -1
- data/sig/active_record_compose.rbs +11 -10
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9038b3106a9206304243a5723488fe400e6c05eba4edb69fef0e2a7a154f15f
|
4
|
+
data.tar.gz: 7432c93447a3627cf6c1e6706d6d0d3d1ea1e6d80079b9038e73fe1fd1bddaeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7ce874d30acf694f7be00c7177a7dcc82a49f8119709fa07b0d9cac98fc4f44ca03211bb104c8d9e2173d42ceebb0de00567c8666e1b1b6adaadd587e60d35ba
|
7
|
+
data.tar.gz: 0f3100317539f2e383ac07fed57f027c90f4030ccd2717fae2e54f288a3f17f92488fa23dc86d6cc80a05746542ef68b780c56b63dd9609ab2f27b39c21a8045
|
data/.rubocop.yml
CHANGED
@@ -6,9 +6,15 @@ AllCops:
|
|
6
6
|
Style/ArgumentsForwarding:
|
7
7
|
Enabled: false
|
8
8
|
|
9
|
+
Style/CommentedKeyword:
|
10
|
+
Enabled: false
|
11
|
+
|
9
12
|
Style/Documentation:
|
10
13
|
Enabled: false
|
11
14
|
|
15
|
+
Style/NumericPredicate:
|
16
|
+
Enabled: false
|
17
|
+
|
12
18
|
Style/StringLiterals:
|
13
19
|
Enabled: true
|
14
20
|
|
@@ -27,6 +33,9 @@ Style/TrailingCommaInArrayLiteral:
|
|
27
33
|
Style/TrailingCommaInHashLiteral:
|
28
34
|
EnforcedStyleForMultiline: comma
|
29
35
|
|
36
|
+
Layout/LeadingCommentSpace:
|
37
|
+
Enabled: false
|
38
|
+
|
30
39
|
Layout/LineLength:
|
31
40
|
Max: 120
|
32
41
|
|
data/CHANGELOG.md
CHANGED
@@ -38,26 +38,23 @@ module ActiveRecordCompose
|
|
38
38
|
extend ActiveSupport::Concern
|
39
39
|
|
40
40
|
included do
|
41
|
-
|
41
|
+
class_attribute :delegated_attributes, instance_writer: false # steep:ignore
|
42
42
|
end
|
43
43
|
|
44
44
|
module ClassMethods
|
45
45
|
# Defines the reader and writer for the specified attribute.
|
46
46
|
#
|
47
47
|
def delegate_attribute(*attributes, to:, **options)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
reader = attribute
|
52
|
-
writer = "#{attribute}="
|
48
|
+
delegates = attributes.flat_map do |attribute|
|
49
|
+
reader = attribute.to_s
|
50
|
+
writer = "#{attribute}="
|
53
51
|
|
54
|
-
|
55
|
-
|
52
|
+
[reader, writer]
|
53
|
+
end
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
55
|
+
delegate(*delegates, to:, **options) # steep:ignore
|
56
|
+
delegated_attributes = (self.delegated_attributes ||= []) # steep:ignore
|
57
|
+
attributes.each { delegated_attributes.push(_1.to_s) }
|
61
58
|
end
|
62
59
|
end
|
63
60
|
|
@@ -66,10 +63,11 @@ module ActiveRecordCompose
|
|
66
63
|
#
|
67
64
|
# @return [Hash] hash with the attribute name as key and the attribute value as value.
|
68
65
|
def attributes
|
69
|
-
attrs =
|
70
|
-
delegates =
|
66
|
+
attrs = defined?(super) ? super : {} # steep:ignore
|
67
|
+
delegates = delegated_attributes # steep:ignore
|
71
68
|
|
72
|
-
# @type var
|
69
|
+
# @type var attrs: Hash[String, untyped]
|
70
|
+
# @type var delegates: Array[String]
|
73
71
|
attrs.merge(delegates.to_h { [_1, public_send(_1)] })
|
74
72
|
end
|
75
73
|
end
|
@@ -15,9 +15,20 @@ module ActiveRecordCompose
|
|
15
15
|
delegate :errors, to: :model
|
16
16
|
|
17
17
|
# @return [Symbol] :save or :destroy
|
18
|
-
def context
|
18
|
+
def context #: ActiveRecordCompose::context
|
19
19
|
c = @context
|
20
|
-
ret =
|
20
|
+
ret =
|
21
|
+
if c.is_a?(Proc)
|
22
|
+
if c.arity == 0
|
23
|
+
# @type var c: ^() -> context
|
24
|
+
c.call
|
25
|
+
else
|
26
|
+
# @type var c: ^(_ARLike) -> context
|
27
|
+
c.call(model)
|
28
|
+
end
|
29
|
+
else
|
30
|
+
c
|
31
|
+
end
|
21
32
|
ret.presence_in(%i[save destroy]) || :save
|
22
33
|
end
|
23
34
|
|
@@ -65,7 +76,7 @@ module ActiveRecordCompose
|
|
65
76
|
# @return [Boolean]
|
66
77
|
def ==(other)
|
67
78
|
return false unless self.class == other.class
|
68
|
-
return false unless
|
79
|
+
return false unless __raw_model == other.__raw_model # steep:ignore
|
69
80
|
return false unless context == other.context
|
70
81
|
|
71
82
|
true
|
@@ -14,7 +14,7 @@ module ActiveRecordCompose
|
|
14
14
|
def each
|
15
15
|
return enum_for(:each) unless block_given?
|
16
16
|
|
17
|
-
|
17
|
+
models.each { yield _1.__raw_model } # steep:ignore
|
18
18
|
self
|
19
19
|
end
|
20
20
|
|
@@ -73,7 +73,7 @@ module ActiveRecordCompose
|
|
73
73
|
def __each_by_wrapped
|
74
74
|
return enum_for(:__each_by_wrapped) unless block_given?
|
75
75
|
|
76
|
-
|
76
|
+
models.each { yield _1 if _1.__raw_model } # steep:ignore
|
77
77
|
self
|
78
78
|
end
|
79
79
|
|
@@ -82,9 +82,11 @@ module ActiveRecordCompose
|
|
82
82
|
def models = @models ||= []
|
83
83
|
|
84
84
|
def wrap(model, context:)
|
85
|
-
if model.is_a?(ActiveRecordCompose::InnerModel)
|
85
|
+
if model.is_a?(ActiveRecordCompose::InnerModel) # steep:ignore
|
86
|
+
# @type var model: ActiveRecordCompose::InnerModel
|
86
87
|
model
|
87
88
|
else
|
89
|
+
# @type var model: ActiveRecordCompose::_ARLike
|
88
90
|
ActiveRecordCompose::InnerModel.new(model, context:)
|
89
91
|
end
|
90
92
|
end
|
@@ -20,7 +20,7 @@ module ActiveRecordCompose
|
|
20
20
|
validate :validate_models
|
21
21
|
|
22
22
|
def initialize(attributes = {})
|
23
|
-
|
23
|
+
super
|
24
24
|
end
|
25
25
|
|
26
26
|
# Save the models that exist in models.
|
@@ -150,7 +150,7 @@ module ActiveRecordCompose
|
|
150
150
|
|
151
151
|
def models = @__models ||= ActiveRecordCompose::InnerModelCollection.new
|
152
152
|
|
153
|
-
def wrapped_models =
|
153
|
+
def wrapped_models = models.__each_by_wrapped # steep:ignore
|
154
154
|
|
155
155
|
def validate_models = wrapped_models.select { _1.invalid? }.each { errors.merge!(_1) }
|
156
156
|
|
@@ -7,16 +7,22 @@ module ActiveRecordCompose
|
|
7
7
|
|
8
8
|
module ClassMethods
|
9
9
|
def lease_connection
|
10
|
-
if
|
11
|
-
|
10
|
+
if ar_class.respond_to?(:lease_connection)
|
11
|
+
ar_class.lease_connection # steep:ignore
|
12
12
|
else
|
13
|
-
|
13
|
+
ar_class.connection
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def connection =
|
17
|
+
def connection = ar_class.connection
|
18
|
+
|
19
|
+
def with_connection(&) = ar_class.with_connection(&) # steep:ignore
|
18
20
|
|
19
21
|
def composite_primary_key? = false
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def ar_class = ActiveRecord::Base
|
20
26
|
end
|
21
27
|
|
22
28
|
def id = nil
|
@@ -5,7 +5,6 @@ module ActiveRecordCompose
|
|
5
5
|
VERSION: String
|
6
6
|
|
7
7
|
interface _ARLike
|
8
|
-
def is_a?: (untyped) -> bool
|
9
8
|
def save: -> bool
|
10
9
|
def save!: -> untyped
|
11
10
|
def destroy: -> bool
|
@@ -13,13 +12,11 @@ module ActiveRecordCompose
|
|
13
12
|
def invalid?: -> bool
|
14
13
|
def valid?: -> bool
|
15
14
|
def errors: -> untyped
|
16
|
-
def ==: (untyped) -> bool
|
17
15
|
end
|
18
16
|
|
19
17
|
type attribute_name = (String | Symbol)
|
20
|
-
type
|
21
|
-
type context_proc = ^(_ARLike) ->
|
22
|
-
type context = context_types | context_proc
|
18
|
+
type context = (:save | :destroy)
|
19
|
+
type context_proc = ((^() -> context) | (^(_ARLike) -> context))
|
23
20
|
|
24
21
|
module DelegateAttribute
|
25
22
|
extend ActiveSupport::Concern
|
@@ -37,20 +34,20 @@ module ActiveRecordCompose
|
|
37
34
|
|
38
35
|
def each: () { (_ARLike) -> void } -> InnerModelCollection | () -> Enumerator[_ARLike, self]
|
39
36
|
def <<: (_ARLike) -> self
|
40
|
-
def push: (_ARLike, ?context: context) -> self
|
37
|
+
def push: (_ARLike, ?context: (context | context_proc)) -> self
|
41
38
|
def empty?: -> bool
|
42
39
|
def clear: -> self
|
43
|
-
def delete: (_ARLike | InnerModel, ?context:
|
40
|
+
def delete: (_ARLike | InnerModel, ?context: (context | context_proc)) -> InnerModelCollection?
|
44
41
|
|
45
42
|
private
|
46
43
|
def models: -> Array[InnerModel]
|
47
|
-
def wrap: (_ARLike | InnerModel, context: context) -> InnerModel
|
44
|
+
def wrap: (_ARLike | InnerModel, context: (context | context_proc)) -> InnerModel
|
48
45
|
end
|
49
46
|
|
50
47
|
class InnerModel
|
51
|
-
@context: context
|
48
|
+
@context: (context | context_proc)
|
52
49
|
|
53
|
-
def initialize: (_ARLike, ?context: context) -> void
|
50
|
+
def initialize: (_ARLike, ?context: (context | context_proc)) -> void
|
54
51
|
def context: -> context
|
55
52
|
def save: -> bool
|
56
53
|
def save!: -> untyped
|
@@ -101,6 +98,10 @@ module ActiveRecordCompose
|
|
101
98
|
module ClassMethods
|
102
99
|
def connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
|
103
100
|
def lease_connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
|
101
|
+
def with_connection: [T] () { () -> T } -> T
|
102
|
+
|
103
|
+
private
|
104
|
+
def ar_class: -> singleton(ActiveRecord::Base)
|
104
105
|
end
|
105
106
|
end
|
106
107
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_compose
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hamajyotan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -52,7 +52,7 @@ metadata:
|
|
52
52
|
homepage_uri: https://github.com/hamajyotan/active_record_compose
|
53
53
|
source_code_uri: https://github.com/hamajyotan/active_record_compose
|
54
54
|
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.3.
|
55
|
+
documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.3.3
|
56
56
|
rubygems_mfa_required: 'true'
|
57
57
|
post_install_message:
|
58
58
|
rdoc_options: []
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
71
|
requirements: []
|
72
|
-
rubygems_version: 3.5.
|
72
|
+
rubygems_version: 3.5.11
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: activemodel form object pattern
|