8000 [Feature Request] Handle Lazy Enumerators · Issue #508 · procore-oss/blueprinter · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Feature Request] Handle Lazy Enumerators #508

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

Open
1 task done
nickagliano-st opened this issue Feb 27, 2025 · 1 comment
Open
1 task done

[Feature Request] Handle Lazy Enumerators #508

nickagliano-st opened this issue Feb 27, 2025 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@nickagliano-st
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe

I can't pass a Enumerator::Lazy as a blueprinter association.

Describe the feature you'd like to see implemented

I guess there are a lot of ways to solve this:

Option 1) Blueprinter handles this "forcefully" -- just call .force to load the enumerable.
Option 2) Blueprinter handles this more gracefully, using one of the "consumption" methods, only loading the data when it's actually being used
Option 3) Blueprinter doesn't handle this -- user has to pass loaded data, or hook into pre_render and do it there, or something like that.

IMO it would be pretty cool if there was a graceful handling of this data. Don't know how that fits into the, sort of, engineering principles of blueprinter as a whole, but if something like this does make sense I might be able to help contribute.

(I have a working version that just forces the data to load here)

Describe alternatives you've considered

Like I listed above, I could just call .force

association(:my_association, blueprint: MyAssociatedBlueprint, view: :normal ) do |association, opts|
  opts[:cached_thing].force # force lazy enumerable to evaluate
end

but that doesn't feel very good.

Additional context

No response

@lessthanjacob lessthanjacob self-assigned this Apr 1, 2025
@lessthanjacob lessthanjacob added the enhancement New feature or request label Apr 1, 2025
@lessthanjacob
Copy link
Contributor

Thanks for bringing this up @nickagliano-st (and apologies for the delayed response)!

We've been taking more of an intentional stance that the scope of responsibil 659E ity of blueprinter should begin and end with serialization of data, and shouldn't extend into needing to understand how that data was (or should be) aggregated. This is primarily to prevent blueprinter from becoming too coupled to any particular data persistence implementation (e.g. ActiveRecord, rom-rb, etc.).

However, since this is more of a native Ruby concern, I think it'd be reasonable for the library to handle this situation implicitly.

As far as implementation goes, we'd like to move away from the current array_like? implementation in an upcoming iteration, so while having an additional lazy_array_like? check would be the most tractable approach currently, we may want to reassess if there's a way we'd like to implement this longer term.

In the meantime, though, feel free to open a PR to add this behavior, and we can continue the discussion there!

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

No branches or pull requests

2 participants
0