You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We're using Docile on Avo to manage some parts of our DSL.
We're experiencing an issue where a method call within the block is not executing in the desired context.
Here's a simplified example of the problem:
We'd like to make it as easy as possible to extract methods in the most natuarl way, as a method that they can run inside our custom blocks (panel, tab, sidebar, and more).
When the panel block it's executed the extracted_fields method is not found, so it falls back to the @__fallback__ context which is the resource's context. The problem here is that the code from extracted_fields was called from the panel block with the intention to add a field to that panel, but it was added to the resource.
We've found 2 workarounds
1 - Pass the context to the method
We don't like this approach as it makes the user learn yeat another pattern that they might implement badly and doesn't feel that natural.
defextracted_fields(context)puts"Context inside extracted_fields method: #{self}"context.field:extractedenddeffieldsfield:idpaneldoputs"Context inside panel do block: #{self}"extracted_fields(self)endend
2 - Make extracted_fields return a Proc and instance_exec it
It seems unnatural again to have a method run a block. But mor importantly, they have to call instance_exec inside the panel block which we don't want
Both workarounds require public DSL interaction, and one of our goals is to keep the public DSL as simple as possible.
Ideal scenario(s)
The ideal scenario would be that they declare the methods on the resource file and just rub them inside the custom blocks (panel, tab, sidebar, and more).
If that's impossible, we'd like to expose a simple method call or something similar that would be simple to implement and least destructive.
defextracted_fieldsfield:extractedenddeffieldsfield:idpaneldounpack_fieldsextracted_fields# or maybeunpack_fields->{extracted_fields}endend
Is there a more elegant solution or best practice within Docile to ensure that method calls within a block execute in the expected context while avoiding the need for additional public DSL interactions?
We'd greatly appreciate your help and guidance on this matter.
Thank you!
The text was updated successfully, but these errors were encountered:
Hi,
We're using Docile on Avo to manage some parts of our DSL.
We're experiencing an issue where a method call within the block is not executing in the desired context.
Here's a simplified example of the problem:
Result:
Expected result (ignoring the context prints):
We'd like to make it as easy as possible to extract methods in the most natuarl way, as a method that they can run inside our custom blocks (
panel
,tab
,sidebar
, and more).When the
panel
block it's executed theextracted_fields
method is not found, so it falls back to the@__fallback__
context which is the resource's context. The problem here is that the code fromextracted_fields
was called from thepanel
block with the intention to add a field to that panel, but it was added to theresource
.We've found 2 workarounds
1 - Pass the context to the method
We don't like this approach as it makes the user learn yeat another pattern that they might implement badly and doesn't feel that natural.
2 - Make
extracted_fields
return aProc
andinstance_exec
itIt seems unnatural again to have a method run a block. But mor importantly, they have to call
instance_exec
inside thepanel
block which we don't wantBoth workarounds require public DSL interaction, and one of our goals is to keep the public DSL as simple as possible.
Ideal scenario(s)
The ideal scenario would be that they declare the methods on the resource file and just rub them inside the custom blocks (
panel
,tab
,sidebar
, and more).Next ideal scenario
If that's impossible, we'd like to expose a simple method call or something similar that would be simple to implement and least destructive.
Is there a more elegant solution or best practice within Docile to ensure that method calls within a block execute in the expected context while avoiding the need for additional public DSL interactions?
We'd greatly appreciate your help and guidance on this matter.
Thank you!
The text was updated successfully, but these errors were encountered: