def apply_hash_constraint(key, constraint)
name = constraint["name"]
action = constraint["constraint"]
params = constraint["params"]
res = false
skip_end = false
if action and params
arg = params.map {|m| @form[m]}
if String === action
res = self.send("match_#{action}".intern, *arg)
elsif Proc === action
res = action.call(*arg)
end
end
if Regexp === action
if Array(@form[key]).length > 1
index = 0
skip_end = true
Array(@form[key]).each do |value|
m = action.match(value)
res = m[0] if m
if res
@form[key][index] = res if untaint?(key)
else
@form[key].delete_at(index)
constraint = (name) ? name : constraint
@invalid_fields[key] ||= []
unless @invalid_fields[key].include?(constraint)
@invalid_fields[key].push(constraint)
end
nil
end
index += 1
end
else
m = action.match(@form[key].to_s)
res = m[0] if m
end
end
if not skip_end
if res
@form[key] = res if untaint?(key)
else
@form.delete(key)
constraint = (name) ? name : constraint
@invalid_fields[key] ||= []
unless @invalid_fields[key].include?(constraint)
@invalid_fields[key].push(constraint)
end
nil
end
end
end