mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-09 16:18:30 +08:00
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. |
||
|---|---|---|
| .. | ||
| action_base.rb | ||
| base.rb | ||
| contract_base.rb | ||
| nested_contract_type.rb | ||
| options_base.rb | ||
| policy_base.rb | ||
| runner.rb | ||
| steps_inspector.rb | ||