shale-builder 0.4.0 → 0.4.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: da77acaa0e4c63b3155b114625c4da322066c92447ce1297915eac5e4facef71
4
- data.tar.gz: 043214cb3659bc261089c29306082051e1cf14dc222e8852336b9cf9f4dd102e
3
+ metadata.gz: 3a79ea1df97f6d5d49af0d596144d931b5aacea98e142866d7e322497fbeaae5
4
+ data.tar.gz: 59f671f470be89ed4854798843657160c87163de286a867be73c4832bb4a2df2
5
5
  SHA512:
6
- metadata.gz: 2e00a2bbeb8ba5c240543520d7a881e2b10fc3e79cf941250230c5906e7ba85742b31611a04154f45e953ba8ec16a1c6dbbd5dc7c6a72e895d25f646e01a19b7
7
- data.tar.gz: 1f5462ad104ca4ffdb7f68d895a517d70dd67b7fe666da7baed61bddd2c68de101061d992abad6895045cb6dc8c958ec59a57cc39cbc51a8fb56056e1bafd5ed
6
+ metadata.gz: f763a5973d2d15c2a2c314ae61ed61f7455724f624f38852f8cd4d174fe2bf12af7bee2eb37a847b5940f9779fa4ad2960eff6a99259c12d0445d16fb63b8775
7
+ data.tar.gz: e872ffe315cec734fa77af67b1be80efded4b750194e66c2e41d069302b5dc18cc4bd0f3da2932528661cc2fa1d84ff90a08f3326c7052a65030987f5c4685eb
data/CHANGELOG.md CHANGED
@@ -5,9 +5,16 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.4.1] - 2025-10-14
9
+
10
+ [Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.4.0...v0.4.1)
11
+
12
+ ### Changes
13
+ - Fix `Shale::Builder::alias_attribute`, improve changelog
14
+
8
15
  ## [0.4.0] - 2025-10-14
9
16
 
10
- [Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.3.0...v0.2.1)
17
+ [Diff](https://github.com/Verseth/ruby-shale-builder/compare/v0.3.0...v0.4.0)
11
18
 
12
19
  ### Changes
13
20
  - Add `Shale::Builder::NestedValidations`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shale-builder (0.4.0)
4
+ shale-builder (0.4.1)
5
5
  booleans (>= 0.1)
6
6
  shale (< 2.0)
7
7
  sorbet-runtime (> 0.5)
data/README.md CHANGED
@@ -270,43 +270,25 @@ You can easily create aliases for attributes using `alias_attribute`
270
270
  Then you can use it like so
271
271
 
272
272
  ```rb
273
- class AmountType < ::Shale::Mapper
274
- include ::Shale::Builder
275
- include ::ActiveModel::Validations
276
- include ::Shale::Builder::NestedValidations
277
-
278
- attribute :value, ::Shale::Type::Float
279
- attribute :currency, ::Shale::Type::String
280
-
281
- validates :value, presence: true
282
- end
273
+ require 'shale/builder'
283
274
 
284
- class TransactionType < ::Shale::Mapper
285
- include ::Shale::Builder
286
- include ::ActiveModel::Validations
287
- include ::Shale::Builder::NestedValidations
275
+ class Amount < Shale::Mapper
276
+ include Shale::Builder
288
277
 
289
- attribute :cvv_code, ::Shale::Type::String
290
- attribute :amount, AmountType
278
+ attribute :value, Shale::Type::Float
279
+ attribute :currency, Shale::Type::String
291
280
 
292
- validates :cvv_code, presence: true
293
- validates :amount, presence: true
281
+ alias_attribute :val, :value
294
282
  end
295
283
 
296
- obj = TransactionType.build do |t|
297
- t.amount do |a|
298
- a.currency = 'USD'
299
- end
284
+ a = Amount.build do |a|
285
+ a.val = 3.2
300
286
  end
301
287
 
302
- obj.valid? #=> false
303
- obj.errors #=> #<ActiveModel::Errors [#<ActiveModel::Error attribute=cvv_code, type=blank, options={}>, #<ActiveModel::NestedError attribute=amount.value, type=blank, options={}>]>
304
- obj.errors.messages #=> {cvv_code: ["can't be blank"], "amount.value": ["can't be blank"]}
288
+ a.val #=> 3.2
289
+ a.value #=> 3.2
305
290
  ```
306
291
 
307
- You MUST include `ActiveModel::Validations` before `Shale::Builder::NestedValidations`.
308
-
309
-
310
292
  ### Sorbet support
311
293
 
312
294
  Shale-builder adds support for sorbet and tapioca.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Shale
4
4
  module Builder
5
- VERSION = '0.4.0'
5
+ VERSION = '0.4.1'
6
6
  end
7
7
  end
data/lib/shale/builder.rb CHANGED
@@ -140,27 +140,25 @@ module Shale
140
140
  RUBY
141
141
  end
142
142
 
143
- end
144
- mixes_in_class_methods(ClassMethods)
145
-
146
- # Create an alias for the getter and setter of an attribute.
147
- sig { params(new_name: Symbol, old_name: Symbol).void }
148
- def alias_attribute(new_name, old_name)
149
- klass = T.unsafe(self).class
150
-
151
- attr = klass.attributes[old_name]
152
- (attr.aliases ||= []) << new_name
153
-
154
- klass.builder_methods_module.class_eval <<~RUBY, __FILE__, __LINE__ + 1
155
- def #{new_name}
156
- #{old_name}
157
- end
143
+ # Create an alias for the getter and setter of an attribute.
144
+ sig { params(new_name: Symbol, old_name: Symbol).void }
145
+ def alias_attribute(new_name, old_name)
146
+ attr = attributes.fetch(old_name)
147
+ (attr.aliases ||= []) << new_name
148
+
149
+ builder_methods_module.class_eval <<~RUBY, __FILE__, __LINE__ + 1
150
+ def #{new_name}
151
+ #{old_name}
152
+ end
153
+
154
+ def #{new_name}=(val)
155
+ self.#{old_name} = val
156
+ end
157
+ RUBY
158
+ end
158
159
 
159
- def #{new_name}=(val)
160
- self.#{old_name} = val
161
- end
162
- RUBY
163
160
  end
161
+ mixes_in_class_methods(ClassMethods)
164
162
 
165
163
  end
166
164
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shale-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Drewniak