Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ GEM

PLATFORMS
arm64-darwin-22
arm64-darwin-23
x86_64-darwin-22
x86_64-darwin-23
x86_64-linux
Expand Down
15 changes: 0 additions & 15 deletions app/controllers/concerns/gem_class_scoped.rb

This file was deleted.

17 changes: 0 additions & 17 deletions app/controllers/concerns/gem_file_scoped.rb

This file was deleted.

15 changes: 0 additions & 15 deletions app/controllers/concerns/gem_module_scoped.rb

This file was deleted.

30 changes: 0 additions & 30 deletions app/controllers/concerns/gem_scoped.rb

This file was deleted.

22 changes: 0 additions & 22 deletions app/controllers/concerns/gem_target_scoped.rb

This file was deleted.

33 changes: 33 additions & 0 deletions app/controllers/gems/base_controller.rb
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
Comment on lines +16 to +19
Copy link
Copy Markdown
Contributor Author

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_gem finder logic.

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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we should have a general @gem.find_const! where the returned object could then have both module?/class? qualifiers on it.

else
@gem.info.analyzer
end

@namespace = @gem.find_namespace(@target.qualified_namespace) if params[:class_id]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to highlight that we were doing extra work in the params[:class_id] case so I pulled it out to it's own line instead of nestling it into the existing conditional branch.

end
end
5 changes: 2 additions & 3 deletions app/controllers/gems/class_methods_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

class Gems::ClassMethodsController < ApplicationController
include GemScoped
include GemTargetScoped
class Gems::ClassMethodsController < Gems::BaseController
set_target

def show
@method = @target.class_methods.find { |class_method| class_method.name == params[:id] }
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/gems/classes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# frozen_string_literal: true

class Gems::ClassesController < ApplicationController
include GemScoped
include GemClassScoped

class Gems::ClassesController < Gems::BaseController
def index
end

def show
@class = @gem.find_class!(params[:id])

@classes = @gem.classes.select { |klass| klass.qualified_namespace == @class.qualified_name }
@namespace = @gem.find_namespace(@class.qualified_namespace)
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/gems/docs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Gems::DocsController < ApplicationController
include GemScoped

class Gems::DocsController < Gems::BaseController
def index
end

Expand Down
11 changes: 8 additions & 3 deletions app/controllers/gems/files_controller.rb
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
4 changes: 1 addition & 3 deletions app/controllers/gems/guides_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Gems::GuidesController < ApplicationController
include GemScoped

class Gems::GuidesController < Gems::BaseController
def index
end

Expand Down
5 changes: 2 additions & 3 deletions app/controllers/gems/instance_methods_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

class Gems::InstanceMethodsController < ApplicationController
include GemScoped
include GemTargetScoped
class Gems::InstanceMethodsController < Gems::BaseController
set_target

def show
@method = @target.instance_methods.find { |instance_method| instance_method.name == params[:id] }
Expand Down
7 changes: 3 additions & 4 deletions app/controllers/gems/modules_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# frozen_string_literal: true

class Gems::ModulesController < ApplicationController
include GemScoped
include GemModuleScoped

class Gems::ModulesController < Gems::BaseController
def index
end

def show
@module = @gem.find_module!(params[:id])

@modules = @gem.modules.select { |mod| mod.qualified_namespace == @module.qualified_name }
@classes = @gem.classes.select { |klass| klass.qualified_namespace == @module.qualified_name }
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/gems/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Gems::PagesController < ApplicationController
include GemScoped

class Gems::PagesController < Gems::BaseController
def show
render params[:id].to_sym
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/gems/rbs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Gems::RBSController < ApplicationController
include GemScoped

class Gems::RBSController < Gems::BaseController
def index
require_samples = params[:require_samples].present?
signature = @gem.rbs_signature(require_samples:)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/gems/search_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Gems::SearchController < ApplicationController
include GemScoped

class Gems::SearchController < Gems::BaseController
def index
query = params[:q].to_s.downcase

Expand Down
4 changes: 1 addition & 3 deletions app/controllers/gems/types_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class Gems::TypesController < ApplicationController
include GemScoped

class Gems::TypesController < Gems::BaseController
def index
@samples = Types::Sample
.group(:gem_name, :gem_version, :receiver, :method_name)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/gems/versions_controller.rb
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
6 changes: 1 addition & 5 deletions app/controllers/gems_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
# frozen_string_literal: true

class GemsController < ApplicationController
include GemScoped

before_action :set_gem, except: :index

class GemsController < Gems::BaseController
def index
@gems = Gems.just_updated
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/source_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def source_path
"#{gem.unpack_data_path}/#{file}"
end

def existent
self if exist?
end

def exist?
file && gem.files.include?(file) && File.exist?(source_path)
end
Expand Down
2 changes: 0 additions & 2 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ test:
<<: *default
database: gemsh_test
host: localhost
username: postgres
password: postgres
Comment on lines -60 to -61
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down
Loading