-
-
Notifications
You must be signed in to change notification settings - Fork 116
Reduce method visibility where possible #16
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
Conversation
|
@fuadsaud thanks for this PR. Before to proceed, we need to evaluate case by case the methods. For instance, by declaring Also, the test suite doesn't exercise cases like these. We need, to ensure that the "natural" usage is preserved. class VisibilityAction
include Lotus::Action
def call({})
self.body = 'hi'
self.body # void call to check that it doesn't raise an error
body # same for this
end
endWhat do you think? |
|
Yes, indeed; let's discuss it on the diffs. As a side note: this explicit receiver behaviour is a little weird since, there's an exception to it (explicit |
|
@fuadsaud the explicit receiver is necessary for another case: distinguish between a getter and a local variable. class ExplicitReceiverAction
include Lotus::Action
def call(params)
body = ComplexElaboration.run
body # returns the result of ComplexElaboration
self.body # returns the value of @body
end
end |
|
@fuadsaud do you think this is still something that we want to work on? If yes, would you mind to write tests to ensure that explicit receiver would work as expected? I can understand your objection, but we are just two people and this framework will be used in the wild with unforeseen use cases. POLA FTW ;) |
|
Yes, I can, though not sure when I'll have time to do it (if anyone wants to step in and get it done, feel free). Also, do you mind pointing out which methods you think should be left as |
|
@fuadsaud sure, I'll apply the help-wanted label, then. Thanks! |
Many methods that were marked as `protected` didn't actually need to be so. This commit reduces the visibility level of these methods to `private` as possible.
|
@fuadsaud Looks good, but despite the fact that your implementation is formally correct, I'd amend with a few changes, in order to not surprise end users. Look at the following code, where we need to use In other words, I'd not sacrifice correctness for usability here. Your PR is an improvement and rationalizes what should be private and protected, but we can't foresee how people will use those methods in their implementations. require 'lotus/controller'
require 'lotus/action/cookies'
require 'lotus/action/session'
class MyAction
include Lotus::Action
include Lotus::Action::Cookies
include Lotus::Action::Session
self.configuration.handle_exceptions false
def call(params)
self.body = 'x'
self.status = 201
self.format = :json
self.headers.merge!('X-Custom' => 'OK')
# OK to keep them private
# self.configuration
# self.finish
# NOT OK (I'd keep them protected)
# self.response
# self.cookies
# self.session
end
end
action = MyAction.new
puts action.call({}).inspect |
Many methods that were marked as
protecteddidn't actually need to be so.This commit reduces the visibility level of these methods to
privateaspossible.