Module: Virtuatable::Helpers::Fields
- Included in:
- Controllers::Base
- Defined in:
- lib/virtuatable/helpers/fields.rb
Overview
Helpers for the parameters of a request.
Instance Method Summary collapse
-
#check_either_presence(*fields, key:) ⇒ Object
Checks the presence of either fields given in parameters.
-
#check_presence(*fields) ⇒ Object
Checks the presence of several fields given as parameters and halts the execution if it’s not present.
-
#field_defined?(field) ⇒ Boolean
Checks if a given field is defined in the params.
Instance Method Details
#check_either_presence(*fields, key:) ⇒ Object
Checks the presence of either fields given in parameters. It halts with an error only if ALL parameters are not given.
21 22 23 24 25 |
# File 'lib/virtuatable/helpers/fields.rb', line 21 def check_either_presence(*fields, key:) api_bad_request "#{key}.required" if fields.none? do |field| field_defined?(field) end end |
#check_presence(*fields) ⇒ Object
Checks the presence of several fields given as parameters and halts the execution if it’s not present.
10 11 12 13 14 |
# File 'lib/virtuatable/helpers/fields.rb', line 10 def check_presence(*fields) fields.each do |field| api_bad_request "#{field}.required" unless field_defined?(field) end end |
#field_defined?(field) ⇒ Boolean
Checks if a given field is defined in the params
30 31 32 |
# File 'lib/virtuatable/helpers/fields.rb', line 30 def field_defined?(field) !params.nil? && params.key?(field) && params[field] != '' end |