-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add finished macro hook #3612
Add finished macro hook #3612
Conversation
if it would be like this: class Bla < Foo
extra_attributes z: Int32?
end it finished both classes?, schema of Foo, would be |
So the following code prints 2 and not 1, right? class Foo
def bar
1
end
macro finished
def bar
2
end
end
end
puts Foo.new.bar # => 1 or 2 ? It there an order guaranteed for iterating the finished macros across types? |
@asterite Would it be sensible/possible to add |
I think the extend+subclass might be covered if macro inherited is combined with macro finished. Am i right? |
I think the whole mapping must be repeated in the subclass. The problem is that both parsing and generating JSON for an object happens inside I'll try to see how extending JSON mapping can be done, I tried several ways and they all fail because some macro power is missing... (though the original use case of this PR wasn't this one) |
Great feature! Thank you |
Where are these kind of things documented? |
It's not documented because it's experimental. I'm not sure it was a good choice yet. |
I wonder if the good people over at kemal know that its experimental :) https://github.com/kemalcr/kemal/pull/339/files#diff-855bbab0979fea823de24052246e6982R10 |
Well, the whole language is experimental for that matter, until we reach 1.0 I don't quite understand the purpose of that |
@asterite it's for storing objects between |
@sdogruyol Why not add individual properties to HTTP::Context as users need them? |
Fixes #3604 , fixes #2987
This adds a new macro hook:
finished
. I chose that name because it's a past participle and similar/compatible withincluded
,inherited
,extended
. This macro can be thought as if it's placed at the end of the program, though scope is preserved.For example, to define a base JSON mapping and let users extend it with custom (typed) attributes, one would do:
In fact, with this some APIs could be defined more nicely. Imagine a mapping to a DB model:
In fact, we could change JSON.mapping with this "additive" behaviour, though we probably won't do it because mappings are usually pretty well defined and "closed".