lib/active_configuration/setting_proxy.rb
# Checks modifiers and values on this setting for validation errors and, if
# found, adds those errors to this proxy's model's collection of errors.
Checks modifiers and values on this setting for validation errors and, if
found, adds those errors to this proxy's model's collection of errors.
Checks modifiers and values on this setting for validation errors and if found adds those errors to this proxy ' s model ' s collection of errors .
def validate
      errors = Array.new
      [value].flatten.each do |value_with_modifier|
        value    = value_with_modifier[:value]
        modifier = value_with_modifier[:modifier]
        if !option.allowed_values.nil? and !option.allowed_values.include?(value)
          errors << "The value '#{value}' for the '#{option.key}' setting isn't present in the list of allowed values."
        end
        if !option.allowed_format.nil?
          case option.allowed_format
          when 'string'
            if !value.is_a?(String)
              errors << "The value '#{value}' for the '#{option.key}' setting is not a String."
            end
          when 'fixnum'
            if !value.is_a?(Fixnum)
              errors << "The value '#{value}' for the '#{option.key}' setting is not a Fixnum."
            end
          when 'float'
            if !value.is_a?(Float) and !value.is_a?(Fixnum)
              errors << "The value '#{value}' for the '#{option.key}' setting is not a Float."
            end
          when 'boolean'
            if !value.is_a?(TrueClass) and !value.is_a?(FalseClass)
              errors << "The value '#{value}' for the '#{option.key}' setting is not a Boolean."
            end
          when 'email'
            if !value[/^[A-Z0-9_\.%\+\-\']+@(?:[A-Z0-9\-]+\.)+(?:[A-Z]{2,4}|museum|travel)$/i]
              errors << "The value '#{value}' for the '#{option.key}' setting is not an Email Address."
            end
          when 'url'
            if !value[URI.regexp]
              errors << "The value '#{value}' for the '#{option.key}' setting is not a URL."
            end
          end
          if option.allowed_format.is_a?(Regexp) and !value[option.allowed_format]
            errors << "The value '#{value}' for the '#{option.key}' setting is not in the correct format."
          end
        end
        if !modifier.nil? and !option.allowed_modifiers.nil? and !option.allowed_modifiers.include?(modifier)
          errors << "The modifier '#{modifier}' for the '#{option.key}' setting isn't present in the list of allowed modifiers."
        end
      end
      errors.each do |error|
        @manager.configurable.errors.add(:settings, error)
      end
    end
def validate errors = Array . new [ value ] . flatten . each do | value_with_modifier | value = value_with_modifier [ :value ] modifier = value_with_modifier [ :modifier ] if ! option . allowed_values . nil? and ! option . allowed_values . include? ( value ) errors << "The value '#{value}' for the '#{option.key}' setting isn't present in the list of allowed values." end if ! option . allowed_format . nil? case option . allowed_format when 'string' if ! value . is_a? ( String ) errors << "The value '#{value}' for the '#{option.key}' setting is not a String." end when 'fixnum' if ! value . is_a? ( Fixnum ) errors << "The value '#{value}' for the '#{option.key}' setting is not a Fixnum." end when 'float' if ! value . is_a? ( Float ) and ! value . is_a? ( Fixnum ) errors << "The value '#{value}' for the '#{option.key}' setting is not a Float." end when 'boolean' if ! value . is_a? ( TrueClass ) and ! value . is_a? ( FalseClass ) errors << "The value '#{value}' for the '#{option.key}' setting is not a Boolean." end when 'email' if ! value [ / ^[A-Z0-9_ \. % \+ \- \' ]+@(?:[A-Z0-9 \- ]+ \. )+(?:[A-Z]{2,4}|museum|travel)$ /i ] errors << "The value '#{value}' for the '#{option.key}' setting is not an Email Address." end when 'url' if ! value [ URI . regexp ] errors << "The value '#{value}' for the '#{option.key}' setting is not a URL." end end if option . allowed_format . is_a? ( Regexp ) and ! value [ option . allowed_format ] errors << "The value '#{value}' for the '#{option.key}' setting is not in the correct format." end end if ! modifier . nil? and ! option . allowed_modifiers . nil? and ! option . allowed_modifiers . include? ( modifier ) errors << "The modifier '#{modifier}' for the '#{option.key}' setting isn't present in the list of allowed modifiers." end end errors . each do | error | @manager . configurable . errors . add ( :settings , error ) end end
Checks modifiers and values on this setting for validation errors and, if
found, adds those errors to this proxy's model's collection of errors.
Checks modifiers and values on this setting for validation errors and if found adds those errors to this proxy ' s model ' s collection of errors .