-
Notifications
You must be signed in to change notification settings - Fork 687
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
Allow Audited.audit_class= to receive a string class name and return … #648
Conversation
Would it be better to remove the String case and add that to the Readme
I do not understand why this should not work. maybe phortx can describe the problem. |
@@ -13,12 +13,13 @@ class << self | |||
attr_writer :audit_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.
Perhaps you should replace attr_writer
with a manual implementation to avoid the overhead in the getter:
def audit_class=(cls)
@audit_class = cls.is_a?(String) ? cls.constantize : cls
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.
I had it like this in my first draft but I think it would not help.
The constantize would be called directly on the setting (in the initializer).
I think it would be the same as writing: Audited.audit_class = "CustomAudit".constantize
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.
Oh, that's an interesting thing. Perhaps a comment in the audit_class
why it's there (like "it has to be lazy") could help future readers.
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 tried to add a comment :)
@@ -13,12 +13,13 @@ class << self | |||
attr_writer :audit_class | |||
|
|||
def audit_class | |||
@audit_class ||= "Audited::Audit" | |||
@audit_class = @audit_class.constantize if @audit_class.is_a?(String) |
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 do not like this case but it is better than the old unmemorized audit_class.constantize
in audit_model
4074f53
to
5d67b8c
Compare
5d67b8c
to
b828848
Compare
Thanks for this. I've opened theforeman/foreman#9595 to unpin again. Let's see if CI agrees this works :) |
…an class