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
Fold private methods into the :render
method as local variables
#327
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since
context
could theoretically change (and therefore the code should reflect this), I'd feel more comfortable with an approach using the context's hash (the number Ruby assigns to each unique object):etc.
In this model, we always pass
context
down through the methods, making them pure functions, instead of relying on@context
being set (and therefore acting more like Object methods relying on state). What do you think about an approach like this?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.
From the source-code on
master
, the only place@context
is ever used in this Liquid tag instance is to get the site config:jekyll-feed/lib/jekyll-feed/meta-tag.rb
Lines 19 to 21 in 653999c
Since the site config shouldn't be changing once
site.render
phase starts, memoizing with a hash-store therefore seems wasteful to me...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.
@context
is required to be set forJekyll::Filters::URLFilters
to work.So the suggested model is not applicable.
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.
The code as it exists today has a
render
method that takes in acontext
. That means thatrender
should respond to changes incontext
. From a strict read of just the method signatures, one would expect that inputting new information intocontext
and passing it torender
would yield a different result. I think the only way to fix this that can use an object-method approach is to doMetaTag.new(context).render
and update everything accordingly. The problem stems from the programmer's expectation thatf(input)
should always takeinput
into account rather than just the input to the first call tof()
. This hybrid it's-a-function-but-we-treat-it-like-an-object relies on implicit understanding of the implementation, which could change. The function signatures should reflect this and move fully into an object approach, or use a pure function approach instead.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.
Okay @parkr.
To avoid further bike-shedding, I've decided to not memoize at all..
(since this tag is typically used once per
page
and hence thecontext.hash
is never constant)I have refactored the whole implementation to not call private methods at all.
Is the current diff acceptable to you?