Class: Servactory::Maintenance::Attributes::Validations::Must
- Defined in:
- lib/servactory/maintenance/attributes/validations/must.rb
Class Method Summary collapse
- .check(context:, attribute:, value:, check_key:, check_options:) ⇒ Object
- .should_be_checked_for?(attribute, check_key) ⇒ Boolean
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(context:, attribute:, value:, check_options:) ⇒ Must
constructor
A new instance of Must.
Constructor Details
#initialize(context:, attribute:, value:, check_options:) ⇒ Must
Returns a new instance of Must.
20 21 22 23 24 25 26 27 |
# File 'lib/servactory/maintenance/attributes/validations/must.rb', line 20 def initialize(context:, attribute:, value:, check_options:) super() @context = context @attribute = attribute @value = value @check_options = end |
Class Method Details
.check(context:, attribute:, value:, check_key:, check_options:) ⇒ Object
8 9 10 11 12 |
# File 'lib/servactory/maintenance/attributes/validations/must.rb', line 8 def self.check(context:, attribute:, value:, check_key:, check_options:) return unless should_be_checked_for?(attribute, check_key) new(context:, attribute:, value:, check_options:).check end |
.should_be_checked_for?(attribute, check_key) ⇒ Boolean
14 15 16 |
# File 'lib/servactory/maintenance/attributes/validations/must.rb', line 14 def self.should_be_checked_for?(attribute, check_key) check_key == :must && attribute.must_present? end |
Instance Method Details
#check ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/servactory/maintenance/attributes/validations/must.rb', line 29 def check @check_options.each do |code, | , reason, = (code, ) next if .blank? add_error_with(, code, reason, ) end errors end |