On 05/10/2013 00:07, Jeremy Evans wrote:
> On Friday, October 4, 2013 1:20:40 PM UTC-7, John Anderson wrote:
>     I've been doing some work with ASTTransformer which is really
>     useful. It
>     would be even more useful if it had something like this in the v
>     method:
> 
>         when Sequel::Dataset
>           opts = v( obj.send(:opts) )
> 
>           # preserve row_proc and other stuff
>           dataset = obj.clone
> 
>           # reset opts after clone, because clone does a merge, so
>           # opts which were removed by the transform process will
>           # still be there in the new dataset.
>           dataset.instance_variable_set '@opts', opts
>           dataset
> 
>     Reason being you can then pass a dataset instance into an
>     ASTTransformer
>     subclass and get back another dataset. It will then also handle nested
>     datasets, ie datasets with a dataset as the value of the :from opt. I
>     beat my head on those two for a while... ;-)
> 
> 
> Isn't the above equivalent to:
> 
>   when Sequel::Dataset
>     obj.clone(v(obj.opts))

Except when a key exists in obj.opts but not in v(obj.opts), and the
intent is to remove it.

My use case needs to remove expressions, which can bubble up to removing
an entire WHERE or ORDER BY. I now see I can do that by setting those
keys to false rather than removing them from the new opts hash.

Works for :where and :order.

> I'm not sure this is a wise default for ASTTransformer itself, though. 
> I can see at least Dataset#qualify not doing the correct thing in this case.
> 
> Note that handling Sequel::Dataset in a subclass of ASTTransformer may
> be fine, but you'll probably want transformer specific behavior in those
> cases.

My assumption was that ASTTransformer would do a deep transform by
default, which turned out to be wrong. Where I ran into trouble was

1) finding out how to transform a Dataset into another Dataset using
ASTTransformer. As compared to transforming a set of opts.

2) finding out why nested datasets didn't get processed by the transform.

In essence, what threw me off is that Dataset is implicitly an
expression in the AST, except for in ASTTransformer#v.

ciao
John

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to