Class: DatabaseValidations::Validations::BelongsToPresenceValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- DatabaseValidations::Validations::BelongsToPresenceValidator
- Defined in:
- lib/database_validations/validations/belongs_to_presence_validator.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
-
.kind ⇒ Object
This is a hack to simulate presence validator It’s used for cases when some 3rd parties are relies on the validators For example, required option from simple_form checks the validator.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ BelongsToPresenceValidator
constructor
A new instance of BelongsToPresenceValidator.
- #validate(record) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BelongsToPresenceValidator
Returns a new instance of BelongsToPresenceValidator.
13 14 15 16 |
# File 'lib/database_validations/validations/belongs_to_presence_validator.rb', line 13 def initialize( = {}) @attributes = [[:relation]] super end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
4 5 6 |
# File 'lib/database_validations/validations/belongs_to_presence_validator.rb', line 4 def attributes @attributes end |
Class Method Details
.kind ⇒ Object
This is a hack to simulate presence validator It’s used for cases when some 3rd parties are relies on the validators For example, required option from simple_form checks the validator
9 10 11 |
# File 'lib/database_validations/validations/belongs_to_presence_validator.rb', line 9 def self.kind :presence end |
Instance Method Details
#validate(record) ⇒ Object
18 19 20 21 22 |
# File 'lib/database_validations/validations/belongs_to_presence_validator.rb', line 18 def validate(record) return unless record.public_send([:column]).blank? && record.public_send([:relation]).blank? record.errors.add([:relation], :blank, message: :required) end |