active_record_compose 0.3.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c83677cc55d1c45bfa440db7ca21b2924ffec080a025503b892ec3f0245a6b8
4
- data.tar.gz: d5a01db0286b3bb0527b4e16692b62fa468035fc091449e7607f2f709b75b866
3
+ metadata.gz: 9d71146cd07fcae3e2ba02f5a3130d3eab0cba06dc405584793fa30d4add22ad
4
+ data.tar.gz: 88e70c5d2c6f8327c03c658304d6b036636f9b9ef4f342a45dd2afc7cc1cda4f
5
5
  SHA512:
6
- metadata.gz: 44a5cca81d044619077855a534063bd2a28a42ece83f34b2605c6c03192f89066e14b8e3c02309e6c52d25608fe2dad0b519cfd9a32ed3d8f1f8fc76ec1105e2
7
- data.tar.gz: 2245da3f3053b93ba7c6c2357eecb08a3c069d99e90645fd0a4c7a2b55b5704fc59dbd22e7a70a1f49d397a59cf9c864c39681eb0d7f65d885f797fe973e95a4
6
+ metadata.gz: 76b5dd94c5246ca424564721a9f185488c1d51dcb12177a08c1d103110e05fd510b87f1cb2811256ab1d0d30425f327e8e1179e4c7e62ea3377fd155a708be9e
7
+ data.tar.gz: 7e03b2ea7f423047f5eda1ea89b80b586d7ab3c4ad7d616562a6aa9a555e846336f67f30e5e4b45a28e68913091ea5f3e00aee360f22c0689263380b734d0f3f
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
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.2] - 2024-04-10
4
+
5
+ - support `ActiveRecord::Base#with_connection`
6
+ - rbs maintained.
7
+ - relax context proc arity.
8
+
3
9
  ## [0.3.1] - 2024-03-17
4
10
 
5
11
  - purge nodoc definitions from type signature
@@ -45,15 +45,15 @@ module ActiveRecordCompose
45
45
  # Defines the reader and writer for the specified attribute.
46
46
  #
47
47
  def delegate_attribute(*attributes, to:, **options)
48
- __skip__ =
49
- begin
50
- delegates = attributes.flat_map do |attribute|
51
- reader = attribute
52
- writer = "#{attribute}="
48
+ delegates = attributes.flat_map do |attribute|
49
+ reader = attribute.to_s
50
+ writer = "#{attribute}="
53
51
 
54
- [reader, writer]
55
- end
52
+ [reader, writer]
53
+ end
56
54
 
55
+ __skip__ =
56
+ begin
57
57
  delegate(*delegates, to:, **options)
58
58
  delegated_attributes = (self.delegated_attributes ||= [])
59
59
  attributes.each { delegated_attributes.push(_1.to_s) }
@@ -69,7 +69,8 @@ module ActiveRecordCompose
69
69
  attrs = __skip__ = defined?(super) ? super : {}
70
70
  delegates = __skip__ = delegated_attributes
71
71
 
72
- # @type var delegates: Array[untyped]
72
+ # @type var attrs: Hash[String, untyped]
73
+ # @type var delegates: Array[String]
73
74
  attrs.merge(delegates.to_h { [_1, public_send(_1)] })
74
75
  end
75
76
  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 = c.is_a?(Proc) ? c.call(model) : c
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
 
@@ -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 (__skip__ = model.is_a?(ActiveRecordCompose::InnerModel))
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
@@ -7,16 +7,22 @@ module ActiveRecordCompose
7
7
 
8
8
  module ClassMethods
9
9
  def lease_connection
10
- if ActiveRecord::Base.respond_to?(:lease_connection)
11
- __skip__ = ActiveRecord::Base.lease_connection
10
+ if ar_class.respond_to?(:lease_connection)
11
+ __skip__ = ar_class.lease_connection
12
12
  else
13
- ActiveRecord::Base.connection
13
+ ar_class.connection
14
14
  end
15
15
  end
16
16
 
17
- def connection = ActiveRecord::Base.connection
17
+ def connection = ar_class.connection
18
+
19
+ def with_connection(&) = __skip__ = ar_class.with_connection(&)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordCompose
4
- VERSION = '0.3.1'
4
+ VERSION = '0.3.2'
5
5
  end
@@ -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 context_types = (:save | :destroy)
21
- type context_proc = ^(_ARLike) -> context_types
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: context_types) -> InnerModelCollection?
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.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - hamajyotan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-16 00:00:00.000000000 Z
11
+ date: 2024-04-10 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.1
55
+ documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.3.2
56
56
  rubygems_mfa_required: 'true'
57
57
  post_install_message:
58
58
  rdoc_options: []