-
Notifications
You must be signed in to change notification settings - Fork 105
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
Add in ability to dynamically load in deny_listed domains #249
base: main
Are you sure you want to change the base?
Conversation
class TestDynamicDomainModel | ||
def self.where(*); end | ||
|
||
def self.column_names | ||
[domain_attribute].compact | ||
end | ||
|
||
def self.exists?(hash) | ||
value = hash[self.domain_attribute.to_sym] | ||
return false if value.nil? | ||
|
||
existng_array = self.domain_attribute_values | ||
existng_array.include?(value) | ||
end | ||
|
||
def self.domain_attribute | ||
@domain_attribute ||= "domain" | ||
end | ||
|
||
def self.domain_attribute_values | ||
@domain_attribute_values ||= [] | ||
end | ||
|
||
def self.domain_attribute=(new_domain_attribute) | ||
@domain_attribute = new_domain_attribute | ||
@domain_attribute_values = domain_attribute_values | ||
end | ||
|
||
def self.domain_attribute_values=(new_domain_attribute_values) | ||
@domain_attribute_values = new_domain_attribute_values | ||
end | ||
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.
This is kind of a fake class we can use to test the hash for setting an active record query
Small bump here @micke -- Let me know what you think! |
Thank you for your work and sorry for taking time to review this PR, I've been super busy with work and haven't had any time to spare for this. I can appreciate that you've implemented a nice extendable API, but i'm sorry i don't see how the added complexity makes it worth it. |
@micke You'll need to outline your potential solution more, and perhaps I can refactor this to support that, as I'm not quite sure what you mean. E.g. if we want to support a dynamically generated domain list (a supplied array, a query from ActiveRecord, etc), somewhere we'll need to provide the list of dynamically generated domains, so we could potentially just do a proc like: validates :email, 'valid_email_2/email': { deny_list: proc { |domain_list, domain| domain_list.include?(domain) } } But this proc would take at the very least two arguments: the validates :email, 'valid_email_2/email': { deny_list: proc { |domain_list, domain| domain_list.include?(ValidEmail2::Address.new(self.email).address.domain) } } Is this what you were thinking? |
@scouttyg I'm sorry if i'm unclear. What I'm trying to say is that i appreciate that you've made a nice API to support multiple types of lists, but the way i see it we can achieve that by accepting a proc like this: validates :email, 'valid_email_2/email': { deny_list: ->(domain){ ["google.com"].include?(domain) } }
validates :email, 'valid_email_2/email': { deny_list: ->(domain){ DeniedDomain.where(domain:).exists? } } Or we could also simplify it further by supporting:
That would enable something like this: validates :email, 'valid_email_2/email': { deny_list: ["google.com"] } }
validates :email, 'valid_email_2/email': { deny_list: Set["google.com"] } }
validates :email, 'valid_email_2/email': { deny_list: ->(domain){ DeniedDomain.where(domain:).exists? } } In both versions we would parse the domain and pass it to the proc as the only argument or call |
88300ec
to
909c3ec
Compare
909c3ec
to
511c3ba
Compare
@micke Hmmm, I think the main challenges would lie with the first two cases you list in the last example above, as they are not procs/lambdas: validates :email, 'valid_email_2/email': { deny_list: ["google.com"] } }
validates :email, 'valid_email_2/email': { deny_list: Set["google.com"] } } Because of this, if we are just relying on the "truthiness" of the object, later on we'll still need to inspect that object to determine how to deal with it (e.g. if it's an If we are just mainly supporting procs/lambdas, however, that would make more sense, as we could basically just do: # In ValidEmail2::Address
def deny_listed?
valid? && (domain_is_in?(ValidEmail2.blacklist) || deny_list_lambda.call(address.domain))
end This would still require though that we pass probably a good amount of the Is this more in line with what you are thinking? |
Hey @micke, I've tried to simplify things down a bit, while still doing some validation on the procs / lambdas to make sure things are correct. Let me know what you think, and if this moves us in the right direction! |
i think a straight forward simple and flexible API would be to use a method-name symbol |
Working off of #222, I wanted to add in the ability to load in deny-listed domains from other places outside a
deny_listed_email_domains.yml
file.This new feature should support:
Let me know what you think!