lib/formalizer/form_field.rb
# validate initializer params and raises exceptions unless validation passes
validate initializer params and raises exceptions unless validation passes
validate initializer params and raises exceptions unless validation passes
def validate_params params
      raise FormFieldParamMissing, 'params must be a hash' unless params.class == Hash
      raise FormFieldParamMissing, 'name is requireed' if params[:name].nil?
      names = params[:name].class == Hash ? params[:name].values : [params[:name]]
      names.each do |name_value|
        raise WrongValueClass, 'name should be a String' unless (name_value.is_a?String)
        raise FormFieldParamMissing, 'name cannot be empty' if name_value.empty?
      end
      if [:enum, :multiple].include?(params[:field_type])
        error_message = "enumeration array of >1 items requireed if field_type is enum/multiple"
        enumerations = params[:enumeration].class == Hash ? params[:enumeration].values : [params[:enumeration]]
        raise FormFieldParamMissing, error_message if enumerations.length == 0
        enumerations.each do |enumeration|
          if (!enumeration.is_a?Array) || (enumeration.length < 2)
            raise FormFieldParamMissing, error_message
          end
        end
      end
    end
def validate_params params raise FormFieldParamMissing , 'params must be a hash' unless params . class == Hash raise FormFieldParamMissing , 'name is requireed' if params [ :name ] . nil? names = params [ :name ] . class == Hash ? params [ :name ] . values : [ params [ :name ] ] names . each do | name_value | raise WrongValueClass , 'name should be a String' unless ( name_value . is_a? String ) raise FormFieldParamMissing , 'name cannot be empty' if name_value . empty? end if [ :enum , :multiple ] . include? ( params [ :field_type ] ) error_message = "enumeration array of >1 items requireed if field_type is enum/multiple" enumerations = params [ :enumeration ] . class == Hash ? params [ :enumeration ] . values : [ params [ :enumeration ] ] raise FormFieldParamMissing , error_message if enumerations . length == 0 enumerations . each do | enumeration | if ( ! enumeration . is_a? Array ) || ( enumeration . length < 2 ) raise FormFieldParamMissing , error_message end end end end
validate initializer params and raises exceptions unless validation passes
validate initializer params and raises exceptions unless validation passes
# validating that at least one name_{locale} exists # validate that names are non-empty strings # validating that enumeration exists if field_type is enum or multiple # validates param types
params
<not_specific>