def validate_inclusion(*params)
c = {
:in => nil,
:msg => N::Validation::Errors.no_inclusion,
:allow_nil => false,
:on => :save
}
c.update(params.pop) if params.last.is_a?(Hash)
unless c[:in].respond_to?('include?')
raise(ArgumentError,
'An object that responds to #include? must be supplied as the :in option')
end
for name in params
if c[:allow_nil]
code = %{
unless obj.#{name}.nil? or (#{c[:in].inspect}).include?(obj.#{name})
errors.add(:#{name}, '#{c[:msg]}')
end;
}
else
code = %{
unless (#{c[:in].inspect}).include?(obj.#{name})
errors.add(:#{name}, '#{c[:msg]}')
end;
}
end
__meta[:validations] << [code, c[:on]]
end
end