active_record_compose 0.3.0 → 0.3.1

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: 9253aaba5ac1cc24965caf5b0cd683c7e910b693f91290626318208f3d35f079
4
- data.tar.gz: 57c187fe08e94cdac9a5fd1dc690dea98af686e898be1acaab0ad6a529ca54f6
3
+ metadata.gz: 2c83677cc55d1c45bfa440db7ca21b2924ffec080a025503b892ec3f0245a6b8
4
+ data.tar.gz: d5a01db0286b3bb0527b4e16692b62fa468035fc091449e7607f2f709b75b866
5
5
  SHA512:
6
- metadata.gz: f66509b473e1ddbd2c17ff7f566b684d512e234874178f0cd123bea7eed09877e9198bb4d779f2de0dd0b68f63c675a4a9f2bf529f93d14f531b777a8519f437
7
- data.tar.gz: 0fca4a8c7712faea8eaae1326591059a53684feece7f79ad68eb66a231ed37d635b77d082c7e1590da44c785c7b4c90f8d9cbbbc1665368e826d1c30fa0b5c71
6
+ metadata.gz: 44a5cca81d044619077855a534063bd2a28a42ece83f34b2605c6c03192f89066e14b8e3c02309e6c52d25608fe2dad0b519cfd9a32ed3d8f1f8fc76ec1105e2
7
+ data.tar.gz: 2245da3f3053b93ba7c6c2357eecb08a3c069d99e90645fd0a4c7a2b55b5704fc59dbd22e7a70a1f49d397a59cf9c864c39681eb0d7f65d885f797fe973e95a4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.1] - 2024-03-17
4
+
5
+ - purge nodoc definitions from type signature
6
+ - support `ActiveRecord::Base#lease_connection`
7
+
3
8
  ## [0.3.0] - 2024-02-24
4
9
 
5
10
  - strictify type checking
@@ -38,23 +38,26 @@ module ActiveRecordCompose
38
38
  extend ActiveSupport::Concern
39
39
 
40
40
  included do
41
- class_attribute :delegated_attributes, instance_writer: false
41
+ __skip__ = class_attribute :delegated_attributes, instance_writer: false
42
42
  end
43
43
 
44
- class_methods do
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
- delegates = attributes.flat_map do |attribute|
49
- reader = attribute
50
- writer = "#{attribute}="
48
+ __skip__ =
49
+ begin
50
+ delegates = attributes.flat_map do |attribute|
51
+ reader = attribute
52
+ writer = "#{attribute}="
51
53
 
52
- [reader, writer]
53
- end
54
+ [reader, writer]
55
+ end
54
56
 
55
- delegate(*delegates, to:, **options)
56
- delegated_attributes = (self.delegated_attributes ||= [])
57
- attributes.each { delegated_attributes.push(_1.to_s) }
57
+ delegate(*delegates, to:, **options)
58
+ delegated_attributes = (self.delegated_attributes ||= [])
59
+ attributes.each { delegated_attributes.push(_1.to_s) }
60
+ end
58
61
  end
59
62
  end
60
63
 
@@ -64,7 +67,10 @@ module ActiveRecordCompose
64
67
  # @return [Hash] hash with the attribute name as key and the attribute value as value.
65
68
  def attributes
66
69
  attrs = __skip__ = defined?(super) ? super : {}
67
- attrs.merge(delegated_attributes.to_h { [_1, public_send(_1)] })
70
+ delegates = __skip__ = delegated_attributes
71
+
72
+ # @type var delegates: Array[untyped]
73
+ attrs.merge(delegates.to_h { [_1, public_send(_1)] })
68
74
  end
69
75
  end
70
76
  end
@@ -65,7 +65,7 @@ module ActiveRecordCompose
65
65
  # @return [Boolean]
66
66
  def ==(other)
67
67
  return false unless self.class == other.class
68
- return false unless __raw_model == other.__raw_model
68
+ return false unless (__skip__ = (__raw_model == other.__raw_model))
69
69
  return false unless context == other.context
70
70
 
71
71
  true
@@ -14,7 +14,7 @@ module ActiveRecordCompose
14
14
  def each
15
15
  return enum_for(:each) unless block_given?
16
16
 
17
- models.each { yield _1.__raw_model }
17
+ __skip__ = models.each { yield _1.__raw_model }
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
- models.each { yield _1 if _1.__raw_model }
76
+ __skip__ = models.each { yield _1 if _1.__raw_model }
77
77
  self
78
78
  end
79
79
 
@@ -2,15 +2,16 @@
2
2
 
3
3
  require 'active_record_compose/delegate_attribute'
4
4
  require 'active_record_compose/inner_model_collection'
5
+ require 'active_record_compose/transaction_support'
5
6
 
6
7
  module ActiveRecordCompose
7
8
  class Model
8
9
  include ActiveModel::Model
9
10
  include ActiveModel::Validations::Callbacks
10
11
  include ActiveModel::Attributes
11
- include ActiveRecord::Transactions
12
12
 
13
13
  include ActiveRecordCompose::DelegateAttribute
14
+ include ActiveRecordCompose::TransactionSupport
14
15
 
15
16
  define_model_callbacks :save
16
17
  define_model_callbacks :create
@@ -18,12 +19,6 @@ module ActiveRecordCompose
18
19
 
19
20
  validate :validate_models
20
21
 
21
- # for ActiveRecord::Transactions
22
- class << self
23
- def connection = ActiveRecord::Base.connection
24
- __skip__ = def composite_primary_key? = false
25
- end
26
-
27
22
  def initialize(attributes = {})
28
23
  __skip__ = super(attributes)
29
24
  end
@@ -151,20 +146,11 @@ module ActiveRecordCompose
151
146
  end || raise_on_save_error
152
147
  end
153
148
 
154
- # for ActiveRecord::Transactions
155
- __skip__ = def id = nil
156
-
157
- # for ActiveRecord::Transactions
158
- __skip__ = def trigger_transactional_callbacks? = true
159
-
160
- # for ActiveRecord::Transactions
161
- __skip__ = def restore_transaction_record_state(_force_restore_state) = nil
162
-
163
149
  private
164
150
 
165
151
  def models = @__models ||= ActiveRecordCompose::InnerModelCollection.new
166
152
 
167
- def wrapped_models = models.__each_by_wrapped
153
+ def wrapped_models = (__skip__ = models.__each_by_wrapped)
168
154
 
169
155
  def validate_models = wrapped_models.select { _1.invalid? }.each { errors.merge!(_1) }
170
156
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecordCompose
4
+ module TransactionSupport
5
+ extend ActiveSupport::Concern
6
+ include ActiveRecord::Transactions
7
+
8
+ module ClassMethods
9
+ def lease_connection
10
+ if ActiveRecord::Base.respond_to?(:lease_connection)
11
+ __skip__ = ActiveRecord::Base.lease_connection
12
+ else
13
+ ActiveRecord::Base.connection
14
+ end
15
+ end
16
+
17
+ def connection = ActiveRecord::Base.connection
18
+
19
+ def composite_primary_key? = false
20
+ end
21
+
22
+ def id = nil
23
+
24
+ def trigger_transactional_callbacks? = true
25
+ def restore_transaction_record_state(_force_restore_state = false) = nil # rubocop:disable Style/OptionalBooleanParameter
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordCompose
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.1'
5
5
  end
@@ -24,13 +24,11 @@ module ActiveRecordCompose
24
24
  module DelegateAttribute
25
25
  extend ActiveSupport::Concern
26
26
 
27
- def delegated_attribute: -> Array[untyped]
28
27
  def attributes: -> Hash[String, untyped]
29
- def delegated_attributes: -> Array[untyped]
30
- def delegated_attributes=: (Array[untyped]) -> void
31
28
 
32
- def self.class_attribute: (untyped, ?untyped) -> untyped
33
- def delegate: (*untyped) -> untyped
29
+ module ClassMethods
30
+ def delegate_attribute: (*untyped methods, to: untyped?, **untyped) -> untyped
31
+ end
34
32
  end
35
33
 
36
34
  class InnerModelCollection
@@ -43,7 +41,6 @@ module ActiveRecordCompose
43
41
  def empty?: -> bool
44
42
  def clear: -> self
45
43
  def delete: (_ARLike | InnerModel, ?context: context_types) -> InnerModelCollection?
46
- def __each_by_wrapped: () { (InnerModel) -> void } -> InnerModelCollection | () -> Enumerator[InnerModel, self]
47
44
 
48
45
  private
49
46
  def models: -> Array[InnerModel]
@@ -60,7 +57,6 @@ module ActiveRecordCompose
60
57
  def invalid?: -> bool
61
58
  def valid?: -> bool
62
59
  def ==: (untyped) -> bool
63
- def __raw_model: -> _ARLike
64
60
 
65
61
  private
66
62
  attr_reader model: _ARLike
@@ -70,9 +66,12 @@ module ActiveRecordCompose
70
66
  extend ActiveModel::Callbacks
71
67
  include ActiveModel::Model
72
68
  include ActiveModel::Validations::Callbacks
69
+ extend ActiveModel::Validations::ClassMethods
73
70
  include ActiveModel::Attributes
74
- include ActiveRecord::Transactions
75
71
  include DelegateAttribute
72
+ extend DelegateAttribute::ClassMethods
73
+ include TransactionSupport
74
+ extend TransactionSupport::ClassMethods
76
75
 
77
76
  @__models: InnerModelCollection
78
77
 
@@ -92,8 +91,16 @@ module ActiveRecordCompose
92
91
  def raise_validation_error: -> bot
93
92
  def raise_on_save_error: -> bot
94
93
  def raise_on_save_error_message: -> String
94
+ end
95
+
96
+ module TransactionSupport
97
+ include ActiveRecord::Transactions
98
+
99
+ def id: -> untyped
95
100
 
96
- def self.validate: (*untyped) -> untyped
97
- def run_callbacks: (untyped kind) ?{ () -> untyped } -> untyped
101
+ module ClassMethods
102
+ def connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
103
+ def lease_connection: -> ActiveRecord::ConnectionAdapters::AbstractAdapter
104
+ end
98
105
  end
99
106
  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.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hamajyotan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-24 00:00:00.000000000 Z
11
+ date: 2024-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -42,6 +42,7 @@ files:
42
42
  - lib/active_record_compose/inner_model.rb
43
43
  - lib/active_record_compose/inner_model_collection.rb
44
44
  - lib/active_record_compose/model.rb
45
+ - lib/active_record_compose/transaction_support.rb
45
46
  - lib/active_record_compose/version.rb
46
47
  - sig/active_record_compose.rbs
47
48
  homepage: https://github.com/hamajyotan/active_record_compose
@@ -51,7 +52,7 @@ metadata:
51
52
  homepage_uri: https://github.com/hamajyotan/active_record_compose
52
53
  source_code_uri: https://github.com/hamajyotan/active_record_compose
53
54
  changelog_uri: https://github.com/hamajyotan/active_record_compose/blob/main/CHANGELOG.md
54
- documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.3.0
55
+ documentation_uri: https://www.rubydoc.info/gems/active_record_compose/0.3.1
55
56
  rubygems_mfa_required: 'true'
56
57
  post_install_message:
57
58
  rdoc_options: []