Ruby Struct vs class with Rails ActiveModel Attributes for enterprise scale data

Опубликовано: 21 Февраль 2025
на канале: Winston Codes On
409
20

Sometimes it makes sense to use a "value object" to act as a container for use in your program. Here is a little comparison of Struct vs applying the Rails feature ActiveModel::Attributes to a plain Ruby class.

Source code link (must be a Patreon member to access):
https://github.com/wakproductions-pat...
  / winstonkotzan  

Tip me in BTC! Bitcoin Address: 13FKUusPH1UPvgSkoQRRy6hEg4hyMqKzLS

0:00 Stock filters feature overview
1:11 Rails controller - parameter processing
1:42 Hash value omission new Ruby 3.1 feature
2:31 Comparing Struct vs ActiveModel::Attributes for value objects
4:56 Attributes type coercion
8:47 Attributes documentation / options
9:18 Attributes value object with controller for handling filter params
15:07 Showing frontend form code for filters

Resources:
Ruby discussion on immutable value objects: https://bugs.ruby-lang.org/issues/16122
Hash value omission: https://bugs.ruby-lang.org/issues/14579

Outtro Music:
Carl Casey White Bat Audio - Nightmare City
   • Cyberpunk Synthwave - Nightmare City ...