Class: UffizziCore::ImageCommandArgsValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- UffizziCore::ImageCommandArgsValidator
- Defined in:
- app/validators/uffizzi_core/image_command_args_validator.rb
Instance Method Summary collapse
- #valid_command_args?(raw_command_args) ⇒ Boolean
- #validate_each(record, attribute, command_args) ⇒ Object
Instance Method Details
#valid_command_args?(raw_command_args) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/validators/uffizzi_core/image_command_args_validator.rb', line 8 def valid_command_args?(raw_command_args) return true if raw_command_args.empty? begin command_args = JSON.parse(raw_command_args) rescue JSON::ParserError return false end return false if command_args.class != Array || command_args.empty? command_args.all? { |item| item.instance_of?(String) } end |
#validate_each(record, attribute, command_args) ⇒ Object
4 5 6 |
# File 'app/validators/uffizzi_core/image_command_args_validator.rb', line 4 def validate_each(record, attribute, command_args) record.errors.add(attribute, :invalid) if !command_args.nil? && !valid_command_args?(command_args) end |