-
-
Notifications
You must be signed in to change notification settings - Fork 13
Extract a Gems::BaseController
#479
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
base: main
Are you sure you want to change the base?
Changes from all commits
a6b6663
fd3d98b
d69c6eb
555ed00
5469b10
573ca7c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -329,6 +329,7 @@ GEM | |
|
|
||
| PLATFORMS | ||
| arm64-darwin-22 | ||
| arm64-darwin-23 | ||
| x86_64-darwin-22 | ||
| x86_64-darwin-23 | ||
| x86_64-linux | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| class Gems::BaseController < ApplicationController | ||
| before_action :set_gem | ||
| def self.set_target(...) = before_action(:set_target, ...) | ||
|
|
||
| rescue_from GemNotFoundError, Gems::NotFound do |exception| | ||
| redirect_to gems_path, notice: exception.message | ||
| end | ||
|
|
||
| rescue_from GemConstantNotFoundError do |exception| | ||
| redirect_to gem_version_gem_path(@gem.name, @gem.version), notice: exception.message | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def set_gem | ||
| if gem = params[:gem] | ||
| version = perams[:version] || GemSpec.latest_version_for(gem) | ||
| @gem = GemSpec.find(gem, version) or raise GemNotFoundError.new(gem, version) | ||
| end | ||
| end | ||
|
|
||
| def set_target | ||
| @target = | ||
| case | ||
| when params[:class_id] then @gem.find_class!(params[:class_id]) | ||
| when params[:module_id] then @gem.find_module!(params[:module_id]) | ||
|
Comment on lines
+25
to
+26
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like we should have a general |
||
| else | ||
| @gem.info.analyzer | ||
| end | ||
|
|
||
| @namespace = @gem.find_namespace(@target.qualified_namespace) if params[:class_id] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to highlight that we were doing extra work in the |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,17 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Gems::FilesController < ApplicationController | ||
| include GemScoped | ||
| include GemFileScoped | ||
| class Gems::FilesController < Gems::BaseController | ||
| before_action :set_file | ||
|
|
||
| def index | ||
| end | ||
|
|
||
| def show | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def set_file | ||
| @file = SourceFile.new(gem: @gem, file: params[:id]).existent | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class Gems::VersionsController < ApplicationController | ||
| include GemScoped | ||
|
|
||
| class Gems::VersionsController < Gems::BaseController | ||
| def index | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,8 +57,6 @@ test: | |
| <<: *default | ||
| database: gemsh_test | ||
| host: localhost | ||
| username: postgres | ||
| password: postgres | ||
|
Comment on lines
-60
to
-61
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, didn't mean to commit this. I'm confused why we need this username/password though? |
||
|
|
||
| # As with config/credentials.yml, you never want to store sensitive information, | ||
| # like your database password, in your source code. If your source code is | ||
|
|
||
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 simplify the
set_gemfinder logic.