-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Prefer methods over instance variables #1166
Conversation
@@ -91,7 +91,7 @@ def self.serializer_for(resource, options = {}) | |||
elsif resource.respond_to?(:to_ary) | |||
config.array_serializer | |||
else | |||
options.fetch(:serializer, get_serializer_for(resource.class)) | |||
options.fetch(:serializer) { get_serializer_for(resource.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.
not required for PR, just lazy evals the method when the fetch fails
@scope = options[:scope] | ||
|
||
scope_name = options[:scope_name] | ||
self.object = object |
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.
why prefer self
over just the attribute?
it does differentiate from potential local variables. but I'm curious if there is anything else
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.
why prefer self over just the attribute?
Not sure what you mean by that.
see my answer #1166 (comment)
I'm mostly just confused on when |
@NullVoxPopuli here's the rules for
|
e918fdc
to
28ac9cb
Compare
@_attributes.concat attrs | ||
@_attributes.uniq! | ||
self._attributes.concat(attrs) | ||
self._attributes.uniq! |
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.
So, @beauby you're right that these don't need self
28ac9cb
to
9d65f0a
Compare
👍 |
Prefer methods over instance variables
Just a refactor.
Also, extracted latent Adapter::CachedSerializer class. See comments
Basically, wherever
options
was a method argument in a class, I renamed the@options
ivar toinstance_options
and added an attr_reader. I think it's a good practice to prefer getters/setters over ivars as it gives better failures and encapsulation.Done in response to #1165 which describes a failure where the
options
attribute is confused withoptions
.While changing the options ivars, I just changed all of them.