Custom Rule Path

37 views
Skip to first unread message

James Buckingham

unread,
May 9, 2012, 3:33:52 AM5/9/12
to valida...@googlegroups.com
Hi group,

I'm trying to setup a new ColdBox Module and as part of this I want VT to handle the validation.

VT is passed through as part of the parent project calling the module but ideally I want the module's rules in isolation from the parent.

We're only talking one rule file at the moment so the thought I had was that I could specify a path to my rule for this single time.

Reading the docs though it looks like I can't do that and would be forced down a route of conventions:- http://www.validatethis.org/docs/wiki/How_ValidateThis_Finds_Your_Rules_Definition_Files.cfm#Detailed_Example_of_Locating_Files

Creating a new instance of VT seems a bit OTT at the moment and I'd then have to get my head around how I'd do that within modules.

Does anyone have any suggestions?

Cheers
James

John Whish

unread,
May 9, 2012, 9:03:17 AM5/9/12
to valida...@googlegroups.com
I guess you want a a directory structure like this?

/handers
/model/
/model/User.cfc
/model/User.xml <- rules for User when in the main application
/views/
/module/foobar
/module/foobar/model/User.xml <- rules for User when in the foobar module

I haven't tried it but could you do something like

/model/User.cfc
/model/User.xml <- rules for User when in the main application
/module/foobar/model/User.cfc
/module/foobar/model/User.xml <- rules for User when in the foobar module

Where  /module/foobar/model/User.cfc just looks like:

component extend="model.User" 
{
}

It's a shot in the dark, but it could work...?

John

James

--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To view this discussion on the web visit https://groups.google.com/d/msg/validatethis/-/IcG2FAcMq88J.
To post to this group, send email to valida...@googlegroups.com.
To unsubscribe from this group, send email to validatethis...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/validatethis?hl=en.


James Buckingham

unread,
May 9, 2012, 9:41:41 AM5/9/12
to valida...@googlegroups.com
Thanks John.

At the moment the definitionPath is configured to look in the main project's "model" folder so if I take your example I'd need some way of telling VT it has to go up XX amount of levels and into the module when calling a particular object type.

I just didn't know how I could do that as it's really an exception to the whole thing.

I've gone through a few things this morning and taken the approach of creating a new instance of VT in the module and giving it the module "model" as its definitionPath.

Only stick point I've now got is Coldbox seems to be ignore the VT / ColdBox Interceptor but that seems to be a ColdBox problem at the moment.

Cheers again,
James
To unsubscribe from this group, send email to validatethis+unsubscribe@googlegroups.com.

John Whish

unread,
May 9, 2012, 9:43:44 AM5/9/12
to valida...@googlegroups.com
ValidateThis should look at where the object is on the filesystem and then look for the rule in the same folder, which is why I suggested creating an 'empty' User.cfc which you would then use to validate against and hence get the path. Are you saying that VT still looks at the rule in the root level model folder?

John

To view this discussion on the web visit https://groups.google.com/d/msg/validatethis/-/snfpDDGzUxcJ.

To post to this group, send email to valida...@googlegroups.com.
To unsubscribe from this group, send email to validatethis...@googlegroups.com.

James Buckingham

unread,
May 9, 2012, 10:30:05 AM5/9/12
to valida...@googlegroups.com
Ahh I got you!

To be honest I hadn't tested it out. It was more reading the documentation it doesn't sound like this was going to work.

The catch might be that on this occassion we're dealing with a struct rather than an object - a CFFILE being used to validate photo uploads :-).

I'm guessing for that we'd struggle to get the filesystem path the VT .xml is sitting under? Then again I could populate an object to get around that I guess that then means an extra step.

On this occassion I think I like the fact the VT stuff is being loaded in complete isolation for the module. It at least means if we reuse it elsewhere we've got a self-contained copy of VT managing things at its end.

James

John Whish

unread,
May 9, 2012, 10:33:51 AM5/9/12
to valida...@googlegroups.com
You did used to be able to pass the path in to the validate method, but I'm not sure it still works as it was never an official way to do it :)

For example:

ValidateThis.validate(theObject=myObject,objectType='modules.foobar.model.User')

- John

To view this discussion on the web visit https://groups.google.com/d/msg/validatethis/-/-Stg7IblzGEJ.

To post to this group, send email to valida...@googlegroups.com.
To unsubscribe from this group, send email to validatethis...@googlegroups.com.

James Buckingham

unread,
May 9, 2012, 10:41:19 AM5/9/12
to valida...@googlegroups.com
I did wonder that and it was on my cards to check out (honestly!). You know what it's like though; you start on a solution path and don't turn back :-).

On a side note, for anyone else looking to use the ColdBox VT Interceptor with CB Modules, I had to extend the core VT Interceptor and add a couple of new methods to get ColdBox to load it.

It seems things like Configure() and afterAspectLoad() are for the main CB project not modules. Instead you need to use this:-

<cfcomponent     name="ColdBoxValidateThis" extends="validatethis.extras.coldbox.ColdBoxValidateThisInterceptor">

    <cffunction name="preModuleLoad" access="public" returntype="void" hint="This occurs before any module is loaded in the system " output="false" >
        <cfset Configure() />
        <cfreturn />
    </cffunction>
   
    <cffunction name="postModuleLoad" access="public" returntype="void" hint="This occurs after a module has been loaded in the system " output="false" >
        <cfargument name="event"          required="true" type="any" hint="The event object.">
        <cfargument name="interceptData" required="true" type="struct" hint="interceptData of intercepted info.">
        <cfset afterAspectsLoad(event=arguments.event,interceptData=arguments.interceptData) />
        <cfreturn />
    </cffunction>

Hope that helps someone else.

Cheers,
James

John Whish

unread,
May 9, 2012, 11:26:44 AM5/9/12
to valida...@googlegroups.com
Thanks for the code James, fancy hoping on github... ? :)


James

--
You received this message because you are subscribed to the Google Groups "ValidateThis" group.
To view this discussion on the web visit https://groups.google.com/d/msg/validatethis/-/OI9V742Bhp4J.

James Buckingham

unread,
Aug 30, 2012, 3:22:46 PM8/30/12
to valida...@googlegroups.com, john....@googlemail.com
Ok so it's take me a few months but that's a pull request just gone in for this one:- 

My first time using GIT, I've done the change through the GITHub online editor, so I hope in my noob state I've not broken anything :-)

Cheers,
James

Bob Silverberg

unread,
Aug 30, 2012, 4:49:54 PM8/30/12
to valida...@googlegroups.com, john....@googlemail.com
Thanks James. John is handling the pull requests now, but I'll jump in
and point out the the official repo for VT is actually at
https://github.com/ValidateThis/ValidateThis, not
https://github.com/bobsilverberg/ValidateThis/. The latter is just my
own personal fork, which may or may not be totally up to date.

Can you recreate the pull for https://github.com/ValidateThis/ValidateThis?

Thanks,
Bob
> https://groups.google.com/d/msg/validatethis/-/giNpeWIl0K8J.
>
> To post to this group, send email to valida...@googlegroups.com.
> To unsubscribe from this group, send email to
> validatethis...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/validatethis?hl=en.



--
Bob Silverberg
www.silverwareconsulting.com

James Buckingham

unread,
Aug 30, 2012, 5:07:12 PM8/30/12
to valida...@googlegroups.com, john....@googlemail.com
Ahh ok, sorry.

That was actually the 2nd repo I found as well :-). The first one I tried it on hadn't been updated for 2 years and never noticed till I hit the Interceptor code.

Not a problem though I'll drop that in. Probably tomorrow morning now as I'm about to start winding down for the night.

Cheers,
James

James Buckingham

unread,
Aug 30, 2012, 5:13:47 PM8/30/12
to valida...@googlegroups.com, john....@googlemail.com
Ok - scrap that, I've done it just now :-).

Hopefully that's it right now John.

Cheers,
James
Reply all
Reply to author
Forward
0 new messages