Class: Iry::Constraint::Exclusion
- Inherits:
-
Object
- Object
- Iry::Constraint::Exclusion
- Defined in:
- lib/iry/constraint/exclusion.rb
Instance Attribute Summary collapse
Class Method Summary collapse
-
.infer_name(key, table_name) ⇒ String
Infers the exclusion constraint name based on key and table name.
Instance Method Summary collapse
- #apply(model) ⇒ ActiveModel::Error
-
#initialize(key, name:, message: :taken) ⇒ Exclusion
constructor
A new instance of Exclusion.
Constructor Details
#initialize(key, name:, message: :taken) ⇒ Exclusion
Returns a new instance of Exclusion.
22 23 24 25 26 27 28 29 30 |
# File 'lib/iry/constraint/exclusion.rb', line 22 def initialize( key, name:, message: :taken ) @key = key @message = @name = name end |
Instance Attribute Details
#key ⇒ Symbol
13 14 15 |
# File 'lib/iry/constraint/exclusion.rb', line 13 def key @key end |
#message ⇒ Symbol, String
15 16 17 |
# File 'lib/iry/constraint/exclusion.rb', line 15 def @message end |
#name ⇒ String
17 18 19 |
# File 'lib/iry/constraint/exclusion.rb', line 17 def name @name end |
Class Method Details
.infer_name(key, table_name) ⇒ String
Infers the exclusion constraint name based on key and table name
8 9 10 |
# File 'lib/iry/constraint/exclusion.rb', line 8 def self.infer_name(key, table_name) "#{table_name}_#{key}_excl" end |
Instance Method Details
#apply(model) ⇒ ActiveModel::Error
34 35 36 |
# File 'lib/iry/constraint/exclusion.rb', line 34 def apply(model) model.errors.add(key, ) end |