lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 16 June 2015 at 17:41, Nagaev Boris <bnagaev@gmail.com> wrote:
> I have implemented this [1]. The only difference is that methods with
> parameters are applied with colon not with dot. If a method with
> parameters was applied with dot, then it would be indistinguishable
> from the application of the pipe itself.
> [1] https://gist.github.com/starius/d72f5b2ddc5fd4bf2460

I have also done something, but with dot:
https://github.com/bungle/lua-resty-validation

I think that using colons for parameter functions and dot for parameterless is a good design choice.

I have been thinking about making somekind of rewrite to that lua-resty-validation. Currently I have a few problems though:

1. How should I implement "optional" filters (and what to do with them, skip or continue with next, or should this be parameterized somehow)
2. How should I implement "stop" filters (aka those that skip rest of the chain)
3. How should I implement "default" values (do I need to have this by filters or by filter chain or both)
4. Should I split validation (e.g. true/false checks) and filters (those that modify values) – righth now my implementation supports validators, filters and validating filters (but this might look too much magic).
5. How should I handle absent values (missing values and nils don't neccessarely mean that something is wrong with input, see below).

What I'm trying to do is to implement HTML form validation as neatly as possible:

1. everything (almost) comes in as a string
2. I need to support type conversions
3. some things like checkboxes don't send anything if not checked (so absent values doesn't neccessarily mean that something is wrong with form)
4. usually you want to do simple cleanups like trimming etc.
5. I need to support user defined functions in filter chains (e.g. check if user id is in database and it is valid)


It's pretty hard to come up with nice design, that is easy to use, and easy to understand, and still support some edge cases as well... without too much magic happening.


Regards
Aapo