discourse/lib/service
Loïc Guitaut 89be127ced
DEV: Handle nested attributes in contracts (#36348)
This change adds the ability to validate more complex structures in the
Ruby service contracts.

Contracts were limited to flat structures, which is fine most of the
time, but it can become tedious when managing lots of attributes.

With this new feature, contracts like this one can be defined:
```ruby
attribute :channel_id, :integer

attribute :record, :hash do
  attribute :id, :integer
  attribute :created_at, :datetime
  attribute :enabled, :boolean
end

attribute :user, :hash do
  attribute :username, :string
  attribute :age, :integer

  validates :username, presence: true
end

attribute :items, :array do
  attribute :name, :string

  validates :name, presence: true
end

validates :channel_id, presence: true
```

Two nested types are available: `hash` and `array`.

Each block creates a new contract, meaning coercions, validations and
callbacks are available as usual.
2025-12-12 11:41:48 +01:00
..
action_base.rb
base.rb DEV: Handle nested attributes in contracts (#36348) 2025-12-12 11:41:48 +01:00
contract_base.rb DEV: Handle nested attributes in contracts (#36348) 2025-12-12 11:41:48 +01:00
nested_contract_type.rb DEV: Handle nested attributes in contracts (#36348) 2025-12-12 11:41:48 +01:00
options_base.rb DEV: Provide user input to services using params key 2024-10-25 09:57:59 +02:00
policy_base.rb
runner.rb DEV: Follow-up to the lock step for services 2025-02-06 11:38:15 +01:00
steps_inspector.rb DEV: Add only_if step to DRSF (#35247) 2025-10-08 17:20:22 +02:00