-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
rename context to serialization_context and add url helpers #1289
Conversation
I am not sure about the best way to include url_helpers in the context object. If some people with more knowledge about rails internals have a better idea I am all 👂 :) |
I also feel that in the end |
|
||
def self.default_url_options | ||
ActionMailer::Base.default_url_options | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather not include the url helpers and instead stick 'em in a url_helpers method
We could probably set it and default_url_iptions in the railtie.
Also, i don't believe we include action mailer nor do we need it. There should be a similar methid on the controller
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also add a context test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry about ActionMailer
this is me trying things by copy/pasting from SO in a hurry :( Will look in to how do it from the railtie!
Awesome work! |
b5f42fa
to
88617c7
Compare
Pretty cool 👍 |
LGTM 👍 |
@tchak I'm good with merging this, unless you think |
@NullVoxPopuli let me add a few more tests tonight. Yes |
cool. thanks! |
88617c7
to
d08ee59
Compare
module ActionController | ||
module Serialization | ||
class Context | ||
attr_reader :request_url, :query_parameters, :url_helpers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather have url_helpers
a class method on the Context. It feels more natural here. Also, no need to include them. you could just
class Context
class << self
attr_accessor :url_helpers, :default_url_options
end
end
and in the Railtie
Context.url_helpers = Rails.application.routes.url_helpers # for now, later would like to encapsulate it to control the boundary e.g. UrlHelpers.new(Rails.application.routes.url_helpers)
Context.default_url_options = ActionController::Base.default_url_options
I'm trying to keep in mind how someone using grape would configure this. If we keep a good interface, the details of the implementation don't matter as much. That means more composition and less just mixing things in. Alternatively, there could be a UrlHelpers module that you mix in to the Context when the railtie is called, which allows others to mix in a different helper object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm as far as I understand default_url_options
needs to be defined on the same object where url_helpers
are included in order to be taken in to account. Am I not understanding it correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also I usually use url helpers in serialisers a lot, so I am thinking that at some point I would like to be able to do in some serializer code something like this:
def validation_url
context.validation_url(object)
end
or at least
def validation_url
context.url_helpers.validation_url(object)
end
Are we on the same page here? Or do you see the usage differently?
I am trying to add some tests to |
In my opinion this PR is worth merging without url_helpers (that we could add later). |
I agree, @beauby |
rename context to serialization_context and add url helpers
Wait, it wasn't ready though (there were references to url_helpers and stuff). Could you revert the merge until we clear it for merging? |
that's what I get for not re-reviewing. ha |
@tchak would you mind re-submitting this PR, referencing it, and referring to the comments in #1289 (comment) ? Maybe skip the do it in two parts, without the url helpers, then adding them |
So in the end, how does one access the attribute :url do
serialization_context.url_helpers.posts_route
end |
I think I left this open for the uri templates The serialization context url helpers are mixed into Link. Examples in docs B mobile phone
|
No description provided.