Sha256: 5c0e825be94b5e37a8e8989eb7f36cbb37c715dd2ce0bbc7b0de706e9675f91d
Contents?: true
Size: 1.54 KB
Versions: 3
Compression:
Stored size: 1.54 KB
Contents
# frozen_string_literal: true module Floe module ValidationMixin def self.included(base) base.extend(ClassMethods) end def parser_error!(comment) self.class.parser_error!(name, comment) end def missing_field_error!(field_name) self.class.missing_field_error!(name, field_name) end def invalid_field_error!(field_name, field_value = nil, comment = nil) self.class.invalid_field_error!(name, field_name, field_value, comment) end def workflow_state?(field_value, workflow) workflow.payload["States"] ? workflow.payload["States"].include?(field_value) : true end def wrap_parser_error(field_name, field_value) yield rescue ArgumentError, InvalidWorkflowError => error invalid_field_error!(field_name, field_value, error.message) end module ClassMethods def parser_error!(name, comment) name = name.join(".") if name.kind_of?(Array) raise Floe::InvalidWorkflowError, "#{name} #{comment}" end def missing_field_error!(name, field_name) parser_error!(name, "does not have required field \"#{field_name}\"") end def invalid_field_error!(name, field_name, field_value, comment) # instead of displaying a large hash or array, just displaying the word Hash or Array field_value = field_value.class if field_value.kind_of?(Hash) || field_value.kind_of?(Array) parser_error!(name, "field \"#{field_name}\"#{" value \"#{field_value}\"" unless field_value.nil?} #{comment}") end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
floe-0.13.1 | lib/floe/validation_mixin.rb |
floe-0.13.0 | lib/floe/validation_mixin.rb |
floe-0.12.0 | lib/floe/validation_mixin.rb |