@@ -270,43 +270,25 @@ You can easily create aliases for attributes using `alias_attribute`
270270Then you can use it like so
271271
272272``` 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'
283274
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
288277
289- attribute :cvv_code , :: Shale ::Type ::String
290- attribute :amount , AmountType
278+ attribute :value , Shale ::Type ::Float
279+ attribute :currency , Shale :: Type :: String
291280
292- validates :cvv_code , presence: true
293- validates :amount , presence: true
281+ alias_attribute :val , :value
294282end
295283
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
300286end
301287
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
305290```
306291
307- You MUST include ` ActiveModel::Validations ` before ` Shale::Builder::NestedValidations ` .
308-
309-
310292### Sorbet support
311293
312294Shale-builder adds support for sorbet and tapioca.
0 commit comments