-
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
Adding new has_key_for? method to params #500
Conversation
@@ -3,4 +3,8 @@ module Avram::Paramable | |||
abstract def nested(key : String) : Hash(String, String) | |||
abstract def get?(key : String) | |||
abstract def get(key : String) | |||
|
|||
def has_key_for?(operation : Avram::Operation.class | Avram::SaveOperation.class) : Bool | |||
nested?(operation.param_key).any? |
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 Avram::Params are mainly used to circumvent some testing stuff, the actual specs for this will go in Lucky itself.
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 specs should definitely be here so we know we don't break Avram.
I think we can still test this by making a fake class that implements this Paramable
and then tests that it returns the right thing.
See example here:
avram/spec/operations/nested_save_operation_spec.cr
Lines 17 to 58 in 79668a9
private class NestedParams | |
include Avram::Paramable | |
@business : Hash(String, String) = {} of String => String | |
@email_address : Hash(String, String) = {} of String => String | |
@tax_id : Hash(String, String) = {} of String => String | |
def initialize(@business, @email_address, @tax_id) | |
end | |
def nested?(key : String) : Hash(String, String) | |
if key == "email_address" | |
@email_address | |
elsif key == "tax_id" | |
@tax_id | |
elsif key == "business" | |
@business | |
else | |
raise "What is this key!? #{key}" | |
end | |
end | |
def nested(key : String) : Hash(String, String) | |
nested?(key) | |
end | |
def get?(key) | |
raise "Not implemented" | |
end | |
def get(key) | |
raise "Not implemented" | |
end | |
def nested_file?(key) | |
raise "Not implemented" | |
end | |
def nested_file(key) | |
raise "Not implemented" | |
end | |
end |
I'm gonna merge this in so I can update the Lucky PR |
Fixes #72
This is another in the #369 series.
This doesn't really do much in Avram itself since most of the implementation comes from Lucky::Params.