-
Notifications
You must be signed in to change notification settings - Fork 7
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
Refactor: Use current_conference
instead of set_conference
and conference
(1/3)
#2303
Draft
onk
wants to merge
7
commits into
main
Choose a base branch
from
current_conference_1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ApplicationController has `set_speaker` method. ```ruby def set_speaker if current_user @speaker = Speaker.find_by(email: current_user[:info][:email], conference_id: set_conference.id) end end ``` SpeakerDashboardsController's method is ```ruby def set_speaker @conference ||= Conference.find_by(abbr: params[:event]) if current_user @speaker = Speaker.find_by(conference_id: @conference.id, email: current_user[:info][:email]) @talks = @speaker ? @speaker.talks.not_sponsor : [] end end ``` Only differences are related to setting @talks, so setting of `@talks` into the action. Note: `set_conference` implementation is here. https://github.com/cloudnativedaysjp/dreamkast/blob/6c4b9071bf895dea2f8006184382ed39e1ef885a/app/controllers/application_controller.rb#L128-L130 https://github.com/cloudnativedaysjp/dreamkast/blob/6c4b9071bf895dea2f8006184382ed39e1ef885a/app/controllers/application_controller.rb#L39-L41 ```ruby def set_conference @conference ||= Conference.find_by(abbr: event_name) end def event_name params[:event] end ```
Use ivar `@conference` which is set by `set_conference` instead of `set_conference`'s return value.
…ncerns `set_conference` is now invoked automatically via `before_action` in the `Secured` and `SecuredAdmin` concerns. This change removes the need for explicit calls to `set_conference` in individual controller actions.
github-actions
bot
added
the
reviewapps
Build ReviewApp environment automatically if this label is granted
label
May 5, 2024
Since `Secured` and `SecuredAdmin` modules already include the `set_conference` method as a `before_action`, the ivar `@conference` is consistently available. Remove redundant method calls to `conference`.
Enforce the calling `set_conference` before `set_profile` across controllers to access `@conference` ivar. `Secure` or `SecureAdmin` concerns already called `set_conference` by `before_action`. For api/v1 routes, explicitly call `set_conference` in each controller.
Simplecov Report
|
github-actions
bot
removed
the
reviewapps
Build ReviewApp environment automatically if this label is granted
label
Jul 23, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@conference
set_conference
:set_conference
and use@conference
ivar; instead of using the return value fromset_conference
.set_conference
is always called viabefore_action
:@conference
is always set before any action that using@conference
is executed.conference
Method:conference
method. this can replaced with using@conference
ivar.set byset_conference
.@conference
tocurrent_conference
methodcurrent_conference
:current_conference
that will centralize the access to the conference data.@conference
withcurrent_conference
conference
method:conference
method will be removed from the code base.before_action
:current_conference
reliably setting conference data,set_conference
can be removed frombefore_action
hooks.Motivation
The application currently has four different ways to access the conference data, leading to confusion and inconsistent usage:
set_conference
method:ApplicationController
, sets and returns@conference
.before_action
or not, and its return value is used.conference
method:Secured
andSecuredAdmin
concern modules with the same implementation asset_conference
.before_action
and is called when its return value is needed.@conference
ivar:set_conference
orconference
method.set_conference
isn't always called.Conference.find_by(abbr: params[...])
in actions where neitherbefore_action
nor instance variable setups are in place.This refactor aims to unify and simplify how the conference data is accessed within the application.
After completing these changes, we can use
current_conference
to access the conference data.The chosen method name
current_conference
comes from the commonly usedcurrent_user
and improves readability compared toconference
and avoids confusion with local variables.