Skip to content
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

Merged
merged 2 commits into from
Oct 23, 2020
Merged

Adding new has_key_for? method to params #500

merged 2 commits into from
Oct 23, 2020

Conversation

jwoertink
Copy link
Member

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.

@@ -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?
Copy link
Member Author

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.

Copy link
Member

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:

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

@jwoertink
Copy link
Member Author

I'm gonna merge this in so I can update the Lucky PR

@jwoertink jwoertink merged commit 2a0cd36 into master Oct 23, 2020
@jwoertink jwoertink deleted the issues/72 branch October 23, 2020 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add method to params object to check if it has key for a Form
3 participants