Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby reserved words in filters #4

Closed
nebulon42 opened this issue May 21, 2016 · 5 comments
Closed

Ruby reserved words in filters #4

nebulon42 opened this issue May 21, 2016 · 5 comments

Comments

@nebulon42
Copy link
Contributor

nebulon42 commented May 21, 2016

I'm using a datasource (http://osm2vectortiles.org), which makes extensive use of the column name "class". Using this in filters leads to errors. I think this has something to do with "class" being a reserved word. But also writing on('class'=='residential') yields the following error:

    from /var/lib/gems/1.9.1/gems/glug-0.0.2/lib/glug.rb:244:in `_set_filter'
    from /var/lib/gems/1.9.1/gems/glug-0.0.2/lib/glug.rb:200:in `on'
    from (eval):11:in `block (2 levels) in <main>'
    from /var/lib/gems/1.9.1/gems/glug-0.0.2/lib/glug.rb:89:in `instance_eval'
    from /var/lib/gems/1.9.1/gems/glug-0.0.2/lib/glug.rb:89:in `layer'
    from (eval):5:in `block in <main>'
    from ../glug/bin/glug:5:in `instance_eval'
    from ../glug/bin/glug:5:in `block in <main>'
    from /var/lib/gems/1.9.1/gems/glug-0.0.2/lib/glug.rb:71:in `instance_eval'
    from /var/lib/gems/1.9.1/gems/glug-0.0.2/lib/glug.rb:71:in `initialize'
    from ../glug/bin/glug:5:in `new'
    from ../glug/bin/glug:5:in `<main>'

Is there another way of using reserved words I'm missing or does something in the code of Glug need changing? @systemed

@nebulon42
Copy link
Contributor Author

By looking at the code I was not able to find out how the arguments to the on() function are parsed. It seems that when the first part of the filter expression is either a variable, a reserved word or a string this evaluates to false otherwise to a proper Condition.

@systemed
Copy link
Owner

Glug uses method_missing to interpret conditions. As you've spotted, this won't work where the 'key' is a Ruby reserved word and therefore not missing!

As a workaround, you can define the key as an object explicitly:

_class = Glug::OSMKey.new('class')

and then refer to it from then onwards like this:

on(_class=='residential')

Going forward, I think the best way to solve this would be a short-form version of the above, where you could write tag('class')=='residential' where a reserved word was needed.

@nebulon42
Copy link
Contributor Author

Thanks for the explanation! Your workaround did it for me.

@nebulon42
Copy link
Contributor Author

Fixed in 0a20718.
Can now write e.g. on(tag('class')=='residential').

@systemed
Copy link
Owner

systemed commented Apr 9, 2022

Advance warning: this will change to get('class') in the next version of Glug, for consistency with MBGL expressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants