Permalink
Browse files

Fix most of rubocop warnings

  • Loading branch information...
axilleas committed Jun 15, 2014
1 parent 4901ce2 commit 0a39c2b1a3d3aa47433c52147fe9ecb443e3ea98
Showing with 487 additions and 433 deletions.
  1. +8 −0 .rubocop.yml
  2. +63 −0 .rubocop_todo.yml
  3. +7 −4 app/controllers/application_controller.rb
  4. +18 −18 app/controllers/builds_controller.rb
  5. +14 −17 app/controllers/fedorarpms_controller.rb
  6. +5 −7 app/controllers/rubygems_controller.rb
  7. +12 −17 app/controllers/searches_controller.rb
  8. +1 −1 app/controllers/static_pages_controller.rb
  9. +34 −36 app/controllers/stats_controller.rb
  10. +2 −2 app/helpers/application_helper.rb
  11. +1 −0 app/models/bug.rb
  12. +2 −2 app/models/build.rb
  13. +3 −4 app/models/dependency.rb
  14. +67 −65 app/models/fedora_rpm.rb
  15. +1 −0 app/models/gem_version.rb
  16. +3 −2 app/models/historical_gem.rb
  17. +1 −0 app/models/rpm_version.rb
  18. +47 −50 app/models/ruby_gem.rb
  19. +1 −1 app/views/fedorarpms/index.html.haml
  20. +1 −1 app/views/fedorarpms/show.html.haml
  21. +7 −9 config/application.rb
  22. +1 −1 config/environments/test.rb
  23. +1 −1 config/initializers/encoding_fix.rb
  24. +3 −4 config/initializers/fast_gettext.rb
  25. +1 −1 config/initializers/wrap_parameters.rb
  26. +16 −16 config/routes.rb
  27. +2 −3 db/migrate/20120606144817_create_ruby_gems.rb
  28. +2 −3 db/migrate/20120606144830_create_fedora_rpms.rb
  29. +1 −1 db/migrate/20120724121813_set_dependent_not_null.rb
  30. +1 −1 db/migrate/20120724124409_add_dependency_column.rb
  31. +68 −68 db/schema.rb
  32. +3 −3 features/support/env.rb
  33. +2 −2 spec/controllers/errors_controller_spec.rb
  34. +2 −2 spec/controllers/static_pages_controller_spec.rb
  35. +2 −2 spec/factories/bugs.rb
  36. +10 −13 spec/models/bug_spec.rb
  37. +1 −1 spec/models/build_spec.rb
  38. +1 −1 spec/models/dependency_spec.rb
  39. +1 −1 spec/models/fedora_rpm_spec.rb
  40. +1 −1 spec/models/rpm_version_spec.rb
  41. +1 −1 spec/models/ruby_gem_spec.rb
  42. +1 −1 spec/rails_helper.rb
  43. +5 −5 spec/requests/static_pages_spec.rb
  44. +59 −61 spec/spec_helper.rb
  45. +1 −1 spec/views/errors/error_404.html.haml_spec.rb
  46. +1 −1 spec/views/errors/error_500.html.haml_spec.rb
  47. +1 −1 spec/views/static_pages/contribute.html.haml_spec.rb
  48. +1 −1 spec/views/static_pages/successes.html.haml_spec.rb
View
@@ -0,0 +1,8 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-06-10 14:55:18 +0300 using RuboCop version 0.23.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
#
inherit_from: .rubocop_todo.yml
View
@@ -0,0 +1,63 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-06-15 17:30:31 +0300 using RuboCop version 0.23.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 2
Lint/HandleExceptions:
Enabled: false
# Offense count: 7
Rails/Output:
Enabled: false
# Offense count: 3
Style/BlockNesting:
Max: 5
# Offense count: 3
# Configuration parameters: CountComments.
Style/ClassLength:
Max: 252
# Offense count: 2
Style/CyclomaticComplexity:
Max: 17
# Offense count: 48
Style/Documentation:
Enabled: false
# Offense count: 1
Style/EndOfLine:
Enabled: false
# Offense count: 2
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Enabled: false
# Offense count: 1
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Enabled: false
# Offense count: 65
Style/LineLength:
Max: 299
# Offense count: 11
# Configuration parameters: CountComments.
Style/MethodLength:
Max: 61
# Offense count: 1
Style/MultilineTernaryOperator:
Enabled: false
# Offense count: 9
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/Next:
Enabled: false
@@ -2,15 +2,18 @@ class ApplicationController < ActionController::Base
protect_from_forgery
include FastGettext::Translation
before_filter :set_gettext_locale
before_action :set_gettext_locale
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: lambda { |exception| render_error 500, exception }
rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception }
rescue_from Exception, with: ->(exception) { render_error 500, exception }
rescue_from ActionController::RoutingError, ActionController::UnknownController,
::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound,
with: ->(exception) { render_error 404, exception }
end
private
def render_error(status, exception)
def render_error(status, _exception)
respond_to do |format|
format.html { render template: "errors/error_#{status}", layout: 'layouts/application', status: status }
format.all { render nothing: true, status: status }
@@ -6,19 +6,19 @@ def import
# recursively import all dependencies
@gem.retrieve_metadata
@packages = [{:gem => @gem, :version => @version}]
@packages.each { |p|
p[:gem].dependencies.each { |d|
unless d.dependent_package.nil? ||
@packages.collect { |pkg| pkg[:gem] }.include?(d.dependent_package)
@packages << {:gem => d.dependent_package,
:version => d.dependent_version.split.last}
@packages = [{ gem: @gem, version: @version }]
@packages.each do |p|
p[:gem].dependencies.each do |dep|
unless dep.dependent_package.nil? ||
@packages.map { |pkg| pkg[:gem] }.include?(d.dependent_package)
@packages << { gem: d.dependent_package,
version: d.dependent_version.split.last }
end
}
}
end
end
# build rpms from the deps
@packages.each { |pkg|
@packages.each do |pkg|
# download the gem
pkg[:gem].download_version(pkg[:version])
@@ -31,13 +31,13 @@ def import
spec_file = pkg[:gem].gem2rpm
end
pkg[:spec_path] = spec_file.gsub(/#{Rails.root}\/public/, "")
pkg[:spec_name] = pkg[:spec_path].split("/").last
#pkg[:rpms] = FedoraRpm.build_rpms spec_file
}
pkg[:spec_path] = spec_file.gsub(/#{Rails.root}\/public/, '')
pkg[:spec_name] = pkg[:spec_path].split('/').last
# pkg[:rpms] = FedoraRpm.build_rpms spec_file
end
# TODO run this in a lock
#`createrepo #{Rails.root}/public/rpmbuild/RPMS`
# TODO: Run this in a lock
# `createrepo #{Rails.root}/public/rpmbuild/RPMS`
elsif params[:gem]
@gem = RubyGem.load_or_create params[:gem]
@@ -51,7 +51,7 @@ def import
end
def build
gem = RubyGem.find_by_name(params[:gem])
version = params[:version]
RubyGem.find_by_name(params[:gem])
params[:version]
end
end
@@ -1,11 +1,10 @@
class FedorarpmsController < ApplicationController
helper_method :sort_column, :sort_direction
def index
@page_title = 'Fedora RPMs'
@rpms = FedoraRpm.paginate(:page => params[:page], :per_page => 50).
order(sort_column + ' ' + sort_direction)
@rpms = FedoraRpm.paginate(page: params[:page], per_page: 50)
.order(sort_column + ' ' + sort_direction)
end
def show
@@ -14,10 +13,9 @@ def show
@page_title = @rpm.name
@dependencies = @rpm.dependency_packages
@dependents = @rpm.dependent_packages
#We can register a global error handler inside the application controller for this.
# We can register a global error handler inside the application controller for this.
rescue ActiveRecord::RecordNotFound
redirect_to :action => 'not_found'
redirect_to action: 'not_found'
end
def not_found
@@ -37,15 +35,15 @@ def full_dependencies
@name = params[:id]
@rpm = FedoraRpm.find_by_name(@name)
respond_to do |format|
format.json { render :json => @rpm.json_dependencies }
format.json { render json: @rpm.json_dependencies }
end
end
def full_dependents
@name = params[:id]
@rpm = FedoraRpm.find_by_name(@name)
respond_to do |format|
format.json { render :json => @rpm.json_dependents }
format.json { render json: @rpm.json_dependents }
end
end
@@ -60,23 +58,22 @@ def badge
@total = rpms.size
@commits = 0
@most = nil
rpms.each { |i|
@commits += i.commits
@most = i if @most.nil? || i.commits > @most.commits
}
rpms.each do |rpm|
@commits += rpm.commits
@most = rpm if @most.nil? || rpm.commits > @most.commits
end
@most = @most.shortname
render :layout => false
render layout: false
end
private
private
def sort_column
%w[name commits last_commit_date fedora_user].include?(params[:sort]) ?
%w(name commits last_commit_date fedora_user).include?(params[:sort]) ?
params[:sort] : 'name'
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
%w(asc desc).include?(params[:direction]) ? params[:direction] : 'asc'
end
end
@@ -1,11 +1,10 @@
class RubygemsController < ApplicationController
helper_method :sort_column, :sort_direction
def index
@page_title = 'Ruby Gems'
@gems = RubyGem.paginate(:page => params[:page], :per_page => 50).
order(sort_column + ' ' + sort_direction)
@gems = RubyGem.paginate(page: params[:page], per_page: 50)
.order(sort_column + ' ' + sort_direction)
end
def show
@@ -16,14 +15,13 @@ def show
@dependents = @gem.dependent_packages
end
private
private
def sort_column
%w[name downloads].include?(params[:sort]) ? params[:sort] : 'name'
%w(name downloads).include?(params[:sort]) ? params[:sort] : 'name'
end
def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
%w(asc desc).include?(params[:direction]) ? params[:direction] : 'asc'
end
end
@@ -1,39 +1,34 @@
require 'text'
class SearchesController < ApplicationController
def index
@page_title = 'Search'
searchphrase = params[:id]
@results = RubyGem.where('name LIKE ?', "%#{searchphrase}%").paginate(:page => params[:page], :per_page => 50, :group => "name", :order => "length(name) asc")
@results = RubyGem.where('name LIKE ?', "%#{searchphrase}%").paginate(page: params[:page], per_page: 50, group: 'name', order: 'length(name) asc')
@suggests = []
if @results == []
all_gems = RubyGem.select('name').map{|x| x.name}
dist_score = Hash[all_gems.map{|x| [x, Text::Levenshtein.distance(x, searchphrase)]}]
dist_score = dist_score.sort_by{|x,d| d}.collect{|x,d| x}
sim_score = Hash[all_gems.map{|x| [x, Text::WhiteSimilarity.similarity(x, searchphrase)]}]
sim_score = sim_score.sort_by{|x,s| s}.reverse.collect{|x,s| x}
all_gems = RubyGem.select('name').map { |x| x.name }
dist_score = Hash[all_gems.map { |x| [x, Text::Levenshtein.distance(x, searchphrase)] }]
dist_score = dist_score.sort_by { |_x, d| d }.map { |x, _d| x }
sim_score = Hash[all_gems.map { |x| [x, Text::WhiteSimilarity.similarity(x, searchphrase)] }]
sim_score = sim_score.sort_by { |_x, s| s }.reverse.map { |x, _s| x }
# suggestions are intersection of max similarity and min Levenshtein distance
# 50 is arbitrary, usually it is more than enough to give a good result.
@suggests = sim_score[0..50] & dist_score[0..50]
# give maximum 5 suggestions
@suggests = @suggests[0..4].map{|x| RubyGem.find_by_name(x)}
@suggests = @suggests[0..4].map { |x| RubyGem.find_by_name(x) }
end
end
def suggest_gems (result = [])
@gems = RubyGem.where("name like ?", "%#{params[:q]}%").limit(10)
@gems.each { |g|
result << {:name => g.name}
}
def suggest_gems(result = [])
@gems = RubyGem.where('name like ?', "%#{params[:q]}%").limit(10)
@gems.each { |g| result << { name: g.name } }
respond_to do |format|
format.json { render :json => result.to_json }
format.json { render json: result.to_json }
end
end
def redirect
if params[:search]
redirect_to searches_path + "/#{params[:search]}"
end
redirect_to searches_path + "/#{params[:search]}" if params[:search]
end
end
@@ -6,7 +6,7 @@ def successes
def contribute
@page_title = 'Contribute to make it better'
end
def about
@page_title = 'About'
end
Oops, something went wrong.

0 comments on commit 0a39c2b

Please sign in to comment.