複数カラムをまとめる
適応バージョン
- 1.0.0
- 1.1.0
- 1.1.1
- 1.1.6
- 1.2.0
- 1.2.6
- 2.0.0
- 2.0.1
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.2
- 2.3.8
- 3.0.0
- 3.0.5
- 3.0.7
- 3.0.9
- 3.1.0
- 3.2.3
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.2.1
- 7.0.0
説明
複数カラムを擬似的に1つにまとめる
使い方
モデル.composed_of(条件 [, オプション])
オプション
| オプション | 説明 | 
|---|---|
| :class_name | クラス名 | 
| :mapping | マッピング | 
| :allow_nil | nilのバリデーションをスキップ | 
| :constructor | 条件 | 
| :converter | 新しい値が値オブジェクトに割り当てられたときに呼び出される | 
例
複数カラムを擬似的に1つにまとめる
composed_of :temperature, mapping: %w(reading celsius)
マッピング指定
composed_of :balance, class_name: "Money", mapping: %w(balance amount), converter: Proc.new { |balance| balance.to_money }