Class: Servactory::Inputs::Validations::Required
- Defined in:
- lib/servactory/inputs/validations/required.rb
Class Method Summary collapse
- .check(context:, attribute:, value:, check_key:) ⇒ Object
- .should_be_checked_for?(input, check_key) ⇒ Boolean
Instance Method Summary collapse
- #check ⇒ Object
-
#initialize(context:, input:, value:) ⇒ Required
constructor
A new instance of Required.
Constructor Details
#initialize(context:, input:, value:) ⇒ Required
Returns a new instance of Required.
19 20 21 22 23 24 25 |
# File 'lib/servactory/inputs/validations/required.rb', line 19 def initialize(context:, input:, value:) super() @context = context @input = input @value = value end |
Class Method Details
.check(context:, attribute:, value:, check_key:) ⇒ Object
7 8 9 10 11 |
# File 'lib/servactory/inputs/validations/required.rb', line 7 def self.check(context:, attribute:, value:, check_key:, **) return unless should_be_checked_for?(attribute, check_key) new(context:, input: attribute, value:).check end |
.should_be_checked_for?(input, check_key) ⇒ Boolean
13 14 15 |
# File 'lib/servactory/inputs/validations/required.rb', line 13 def self.should_be_checked_for?(input, check_key) check_key == :required && input.required? end |
Instance Method Details
#check ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/servactory/inputs/validations/required.rb', line 27 def check return if Servactory::Utils.value_present?(@value) _, = @input.required.values_at(:is, :message) add_error_with() end |