From 6a908558ddbc1d4b9295eb41919fc42a134f32e6 Mon Sep 17 00:00:00 2001 From: Navya N Date: Fri, 4 Oct 2024 18:13:02 -0500 Subject: [PATCH] rubocop fixes --- app/controllers/users_controller.rb | 2 + app/controllers/welcome_controller.rb | 3 ++ app/helpers/application_helper.rb | 1 + app/models/application_record.rb | 1 + app/models/user.rb | 1 + bin/bundle | 54 +++++++++++++++------------ 6 files changed, 38 insertions(+), 24 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 54d4df3..ba219f5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +# UsersController handles displaying user-related data. +# The show action retrieves and displays the current user based on the ID provided in the parameters. class UsersController < ApplicationController def show @current_user = User.find(params[:id]) diff --git a/app/controllers/welcome_controller.rb b/app/controllers/welcome_controller.rb index 7395e6d..cdef493 100644 --- a/app/controllers/welcome_controller.rb +++ b/app/controllers/welcome_controller.rb @@ -1,5 +1,8 @@ # frozen_string_literal: true +# WelcomeController handles displaying the public welcome page. +# It skips the login requirement for the index action and redirects logged-in users +# to their user page with a personalized welcome message. class WelcomeController < ApplicationController # Don't require login for the public welcome page skip_before_action :require_login, only: [:index] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 15b06f0..1568d59 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true +# ApplicationHelper is used to store helper methods that can be used across views. module ApplicationHelper end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 08dc537..5e3faa0 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# ApplicationRecord serves as the base class for all models in the application. class ApplicationRecord < ActiveRecord::Base primary_abstract_class end diff --git a/app/models/user.rb b/app/models/user.rb index 4530381..afdd48f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +# The User model represents users in the application. class User < ApplicationRecord validates :email, presence: true end diff --git a/bin/bundle b/bin/bundle index ef688ec..2ffa02a 100755 --- a/bin/bundle +++ b/bin/bundle @@ -22,34 +22,39 @@ m = Module.new do end def cli_arg_version - return unless invoked_as_script? # don't want to hijack other binstubs - return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update` + return unless invoked_as_script? && 'update'.start_with?(ARGV.first || ' ') + extract_bundler_version + end + + def extract_bundler_version bundler_version = nil update_index = nil - ARGV.each_with_index do |a, i| - bundler_version = a if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN) - next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ - bundler_version = Regexp.last_match(1) - update_index = i + ARGV.each_with_index do |arg, index| + if update_index && update_index.succ == index && arg.match?(Gem::Version::ANCHORED_VERSION_PATTERN) + bundler_version = arg + end + + if arg =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = Regexp.last_match(1) + update_index = index + end end + bundler_version end def gemfile gemfile = ENV['BUNDLE_GEMFILE'] - return gemfile if gemfile && !gemfile.empty? - - File.expand_path('../Gemfile', __dir__) + gemfile && !gemfile.empty? ? gemfile : File.expand_path('../Gemfile', __dir__) end def lockfile - lockfile = - case File.basename(gemfile) - when 'gems.rb' then gemfile.sub(/\.rb$/, '.locked') - else "#{gemfile}.lock" - end + lockfile = case File.basename(gemfile) + when 'gems.rb' then gemfile.sub(/\.rb$/, '.locked') + else "#{gemfile}.lock" + end File.expand_path(lockfile) end @@ -73,33 +78,34 @@ m = Module.new do return "#{Gem::Requirement.default}.a" unless version bundler_gem_version = Gem::Version.new(version) - bundler_gem_version.approximate_recommendation end def load_bundler! ENV['BUNDLE_GEMFILE'] ||= gemfile - activate_bundler end def activate_bundler - gem_error = activation_error_handling do - gem 'bundler', bundler_requirement - end + gem_error = activation_error_handling { gem 'bundler', bundler_requirement } return if gem_error.nil? - require_error = activation_error_handling do - require 'bundler/version' - end + require_error = activation_error_handling { require 'bundler/version' } if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION)) return end - warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" + warn_bundler_activation_error(gem_error) exit 42 end + def warn_bundler_activation_error(gem_error) + warn "Activating bundler (#{bundler_requirement}) failed:\n" \ + "#{gem_error.message}\n\n" \ + 'To install the version of bundler this project requires, run ' \ + "`gem install bundler -v '#{bundler_requirement}'`" + end + def activation_error_handling yield nil