Hello all, I’m currently doing a port of Perl’s Data::FormValidator module
to Ruby because I think it would be an extremely useful library to have around,
and I can’t find anything like it on the RAA. Here’s an example usage:
@fv = FormValidator.new
profile = {
:optional => [“company”, “fax”],
:required => [“fullname”, “phone”, “age”]
}
form = {
“company” => “Some Company”,
“fullname” => “Travis Whitton”,
“phone” => “”
}
@fv.setup(form, profile)
@fv.required # => [“age”, “phone”]
or you’ll be able to use a runner and just say:
@fv = FormValidator.new
@fv.validate(form, profile)
which would run an entire suite of tests on the given input storing the result
in instance variables. Of course, it will have more functionality than this,
but on to my question:
Would most people prefer profile to exclusively use symbols, or should it
use the mix of symbols and strings as defined above? I.e.,
symbol version
profile = {
:optional => [:company, :fax],
}
string version
profile = {
:optional => %w{company fax}
}
I’m currently using strings because they’re analogous to keys given to
Ruby’s CGI objects; however, if symbols would be preferred, I’ll go that route.
Also note, the current version is returning arrays of strings in the list
of missing fields, which could also easily be changed. I want to design this
properly the first time, so I don’t have to go back and break the API. Also,
I’m having some weird behaviour with my unit tests where, I have to insert a
blank line at the end of my test, or it will break Test::Unit::TestCase with
the following error:
Loaded suite testvalid
/usr/lib/ruby/site_ruby/1.6/test/unit/util/procwrapper.rb:25:in initialize': unmatched ): /\300\017\022\010Proc:)/ (RegexpError) from /usr/lib/ruby/site_ruby/1.6/test/unit/util/observable.rb:39:in
new’
from /usr/lib/ruby/site_ruby/1.6/test/unit/util/observable.rb:39:in
add_listener' from /usr/lib/ruby/site_ruby/1.6/test/unit/ui/console/testrunner.rb:62:in
attach_to_mediator’
from /usr/lib/ruby/site_ruby/1.6/test/unit/ui/console/testrunner.rb:44:in
start' from /usr/lib/ruby/site_ruby/1.6/test/unit/ui/console/testrunner.rb:21:in
run’
from /usr/lib/ruby/site_ruby/1.6/test/unit.rb:192
from /usr/lib/ruby/site_ruby/1.6/test/unit.rb:164
from testvalid.rb:9
Anybody else had this problem?
Thanks,
Travis Whitton whitton@atlantic.net