How does ez_where catch =~ and co

Hi all,

I’ve been looking through the ez_where plugin and I’m slowly starting to
follow it. One thing that I can’t quite grok is how the
=~ , == , === etc methods are caught in the block.

eg in the readme

condition :my_other_table do
id === [1, 3, 8]
foo == ‘other bar’
fiz =~ ‘%faz%’
end

I can see how the id, foo and fiz methods are caught by using
method_missing, but I can’t find out how the =~ and it’s argument is
then
subsequently caught to be processed.

Can anyone point out how this is done please.

Thanx

On Oct 4, 2006, at 4:08 AM, Daniel N wrote:

fiz =~ ‘%faz%’
end I can see how the id, foo and fiz methods are caught by using
method_missing, but I can’t find out how the =~ and it’s argument
is then subsequently caught to be processed.

Can anyone point out how this is done please.

Thanx

Hey Daniel-

Its actually a dual method_missing dispatch. the id and foo are

caught in Condition by method missing and then they create a new
Clause object for each statement. In the Clause object, method
missing catches the == =~ and other operators. Thats the simplified
explanation anyway. Its quite a complex interaction that has taken us
a while to build up and make work.

Make sure you check out the new version released yesterday!

http://brainspl.at/articles/2006/10/03/nested-joins-and-ez-where-update

-Ezra

On 10/5/06, Ezra Z. [email protected] wrote:

explanation anyway. Its quite a complex interaction that has taken us
a while to build up and make work.

    Make sure you check out the new version released yesterday!

Ruby on Rails Blog / What is Ruby on Rails for?

-Ezra

Hi Ezra,

Thanx for the response. The code is pretty tricky for me to grok.

Hopefully you don’t mind but I’m looking for some inspiration to create
a
plugin to generate nested conditions for javascript.

Basically I’m thinking of a plugin that has similar syntax to ez_where
that
generates conditions based on DOM elements that I can use in an if
statement
to control behaviors and functions on the client side in javascript.

Then I could generate complex conditional statement that conditionally
controlled the visiblity of elements etc.

Does this sound like something that might be useful? When I was looking
through ez_where I was thinking that the logic for the nested conditions
is
essentially the same, with only the output needing to change. I’m not
sure
if that’s true when thinking of dom elements but it’s a place to start.

Thanx to you and Fabien for writing such a great plugin.

Cheers

Hi~

On Oct 4, 2006, at 5:04 PM, Daniel N wrote:

ez_where that generates conditions based on DOM elements that I can
dom elements but it’s a place to start.

Thanx to you and Fabien for writing such a great plugin.

Cheers

Hey Daniel-

I am not entirely sure what you want to do here. Are you trying to

program this in javascript? Or do you mean a ruby/rails coded plugin
that will generate javascript for you? Can you provide me with some
examples of what you are trying to generate and what you would want
your ruby syntax for this to look like? I might be able to point you
in the right direction.

Cheers-
-Ezra

On 10/5/06, Ezra Z. [email protected] wrote:

Cheers-
-Ezra

I’m not exacly sure myself yet of the grand scheme.

At the moment, the overall outcome I want to achive is to be able to
conditionally control visibilty of DOM objects in response to activity
in
the DOM, especially forms.

Something like

form.condition( ‘element5’, :hide ) do
or do
field2 == “go”
and do
thing.hidden?
field1 =~ /bla/
end
end
end

to construct

if ( field2.value = “go” || (thing.style.display = “none” &&
field1.value.match( ‘bla’ ) ) ) { hide_if_shown( element5 ); }

I’m not sure I’m happy with the sytax yet. It looks a bit nasty.

This should be added to an array of conditions that observes form fields
and
gets fired when something happens.

I’d really like to do this in ruby and not need to resort to raw js
unless
nessesary, I’ve been checking out UJS today and that looks like it’s
pretty
nice.

I figured that to do this, first I need to generate the condition inside
the
if statement. Hence my sudden interest in how to construct nested
queries.

I’m hoping that this will lead me to highly interactive and intelligent
forms for the occasions where a large form is required for everything,
but
not everything needs to be filled out, or even wizard style forms on one
page.

Do you have any thoughts on whether this is a reasonable idea or not?
Any
potholes that would be likely if using such a plugin?