Skip to content

Conversation

@kbrock
Copy link
Member

@kbrock kbrock commented Sep 12, 2025

WIP: still have to convert across
WIP: need to verify this doesn't bloat memory too much due to class closure in the lambda

Fixes #203

===

Not thrilled that we are keeping the method closure from virtual_attribute. that has quite a bit of data in there and the lambda

@kbrock kbrock added the wip Work in progress label Sep 12, 2025
arel ||= virtual_delegate_arel(source, to_ref)
elsif block_given?
define_method(name) do
has_attribute?(name) ? self[name] : instance_eval(&block)
Copy link
Member Author

@kbrock kbrock Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so nice.

Before

We can do minimal common manipulations for sql in the TableProxy, but can't do any common manipulation for the ruby code.

After

Adding stuff to ruby like the has_attribute? pattern is a big win.
Besides cutting down on the noise, we often forget to add this block and forgetting it can cause problems at runtime.

@kbrock kbrock changed the title [WIP] Implement Condensed VA syntax [WIP] [POC] Implement Condensed VA syntax Sep 26, 2025
@kbrock kbrock added the enhancement New feature or request label Sep 26, 2025
@miq-bot miq-bot added the stale label Dec 27, 2025
@miq-bot
Copy link
Member

miq-bot commented Dec 27, 2025

This pull request has been automatically marked as stale because it has not been updated for at least 3 months.

If these changes are still valid, please remove the stale label, make any changes requested by reviewers (if any), and ensure that this issue is being looked at by the assigned/reviewer(s).

@miq-bot
Copy link
Member

miq-bot commented Dec 30, 2025

Checked commit kbrock@c0e1033 with ruby 3.1.7, rubocop 1.56.3, haml-lint 0.64.0, and yamllint
2 files checked, 1 offense detected

spec/db/models.rb

@kbrock
Copy link
Member Author

kbrock commented Dec 30, 2025

@Fryguy Where are you on this?
Could merge this and then not make the changes to manageiq/manageiq, or punt. Up to you.

  1. This is fully backwards compatible.
  2. The syntax is denser. (nice/bad)
  3. The double block. (one for arel and the other for ruby is not ideal)
  4. Using define_method creates a block the size of the class for every virtual attribute.

Re 3: If you would like to pair up to derive SQL from Ruby, we can talk. It is very academic and probably not possible. I always think of defunkt/ambition, where he wrote LDAP/SQL from Ruby. Since we are standardized on the Prizm parser, it would have longer staying power.
This would solve the density problem and be slick.

But guessing that improving MiqExpression would be a much better bang for your buck than advanced Ruby/arel generation.

Re 4: This was the reason I aborted this PR. Didn't profile this, but there is a reason why Rails introduced :unless. So they can use :unless => :method_symbol instead of `:if => {|r| !method_symbol} }. And why they introduced all sorts of ways to use symbols instead of blocks for

@Fryguy
Copy link
Member

Fryguy commented Jan 21, 2026

I love this. Waiting on moving forward at the moment though because @jrafanie is doing Rails 8 support first and I don't want to get in his way.

@Fryguy Fryguy self-assigned this Jan 21, 2026
@Fryguy Fryguy removed the stale label Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request wip Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support condensed virtual_attribute definitions

3 participants