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 +4 -4
- data/CHANGELOG.md +8 -1
- data/Gemfile.lock +1 -1
- data/README.md +10 -28
- data/lib/shale/builder/version.rb +1 -1
- data/lib/shale/builder.rb +17 -19
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a79ea1df97f6d5d49af0d596144d931b5aacea98e142866d7e322497fbeaae5
|
4
|
+
data.tar.gz: 59f671f470be89ed4854798843657160c87163de286a867be73c4832bb4a2df2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
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
|
-
|
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
|
285
|
-
include
|
286
|
-
include ::ActiveModel::Validations
|
287
|
-
include ::Shale::Builder::NestedValidations
|
275
|
+
class Amount < Shale::Mapper
|
276
|
+
include Shale::Builder
|
288
277
|
|
289
|
-
attribute :
|
290
|
-
attribute :
|
278
|
+
attribute :value, Shale::Type::Float
|
279
|
+
attribute :currency, Shale::Type::String
|
291
280
|
|
292
|
-
|
293
|
-
validates :amount, presence: true
|
281
|
+
alias_attribute :val, :value
|
294
282
|
end
|
295
283
|
|
296
|
-
|
297
|
-
|
298
|
-
a.currency = 'USD'
|
299
|
-
end
|
284
|
+
a = Amount.build do |a|
|
285
|
+
a.val = 3.2
|
300
286
|
end
|
301
287
|
|
302
|
-
|
303
|
-
|
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.
|
data/lib/shale/builder.rb
CHANGED
@@ -140,27 +140,25 @@ module Shale
|
|
140
140
|
RUBY
|
141
141
|
end
|
142
142
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
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
|