-
Notifications
You must be signed in to change notification settings - Fork 64
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
Implement function criteria #912
Merged
jwoertink
merged 7 commits into
luckyframework:main
from
davidepaolotua:implement-function-criteria
Dec 2, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4ce8af4
Add updated? and created? methods on SaveOperations
davidepaolotua 2c3da91
Merge branch 'main' of https://github.com/jinn999/avram into add-upda…
davidepaolotua 5078688
Implement date function
davidepaolotua a1f93ad
Move upper and lower to new criterias
davidepaolotua 09c82f5
generalize the application of functions to columns
davidepaolotua 6774dae
Put in standby the extra-param function creation
davidepaolotua 5985d25
Final clean up
davidepaolotua File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ module Avram::DefineAttribute | |
ATTRIBUTES = [] of Nil | ||
\{% end %} | ||
|
||
|
||
\{% if [email protected]? %} | ||
\{% for attribute in @type.ancestors.first.constant :ATTRIBUTES %} | ||
\{% ATTRIBUTES << attribute %} | ||
|
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.
If someone passes a Time object to input date, will it do the right thing?
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.
It actually depends on what is the right thing to do. At this moment, it will not be compiling, with this error
Error: expected argument #1 to 'String::Lucky.parse' to be Array(String), Nil or String, not Time
The problem is that the function silently switches the criteria to a string. It's mostly about making a choice on how to represent its outcome in Lucky. Date does not exists and unfortunately, that's what the function is returning. So I had to choose between
Now the problem becomes that the
eq()
expects the other to be of the same type (thus the error), so I had to choose between.as_date.gte("2011-01-01")
oras_date.gte(Time.utc)
, I opted for the first but I think it's really a matter of choices in thereThere 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.
My initial instinct is that it would run the proper .to_s on the Time to get the date out as a string. I can conceive of ways that might not actually be the right thing to do -- though it is what I would have expected.
If there's enough ambiguity in the use case then sure, raising an error is probably the right thing to do. It's a good candidate for a more helpful error message rendered at compile time. If it's possible to lend advice on what actually is expected, that would be a good way to lead folks to the happy path. Eg "Did you mean .eq(time.psql_format)?" or whatever method it would actually be.
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.
There was an other alternative I was thinking about, but it risks becoming quite complicated after a while...
It basically consists of defining a new
Date
class, almost invisible to everyone but the Time::Lucky one, which would then redefine basically all operators with overloading (something like instead of having:criteria(T).eq(other : T)
we would havecriteria(Date).eq(other : String)
andcriteria(Date).eq(other : Time)
.But honestly I don't even know if this is feasible.
Still, this would open the doors also for the Interval class...
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.
Neat idea, but it can wait. Your scope here is nicely consumable as is.