Skip to content

Commit

Permalink
update rubocop config, fix rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mtnstar authored and Michael Rötheli committed Apr 16, 2018
1 parent 2a16a41 commit 6643caf
Show file tree
Hide file tree
Showing 52 changed files with 92 additions and 151 deletions.
35 changes: 35 additions & 0 deletions .rubocop-must.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Rubocop configuration that MUST hold for every build.

AllCops:
DisplayCopNames: true
DisabledByDefault: true
Exclude:
- Rakefile
- db/**/*
- config/**/*
- bin/**/*
- spec/**/*
- vendor/**/*
- tmp/**/*
- frontend/**/*

Metrics/AbcSize:
Max: 17

Metrics/ClassLength:
Max: 200

Metrics/CyclomaticComplexity:
Max: 6

Metrics/LineLength:
Max: 100

Metrics/MethodLength:
Max: 10

Metrics/ModuleLength:
Max: 200

Metrics/ParameterLists:
Max: 4
12 changes: 5 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
# encoding: utf-8

source 'https://rubygems.org'

gem 'rails', '5.1.4'

gem 'active_model_serializers', '~> 0.10.6'
gem 'activerecord-postgresql-adapter'
gem 'airbrake', '~> 5.0'
gem 'annotate'
gem 'carrierwave'
gem 'database_cleaner'
gem 'deep_cloneable', '~> 2.2.2'
gem 'faker'
gem 'odf-report'
gem 'mini_magick'
gem 'mysql2'
gem 'net-ldap', '~> 0.14.0'
gem 'odf-report'
gem 'pg', '0.19.0.pre20160409114042'
gem 'pg_search'
gem 'puma', '~> 3.0'
gem 'rack'
gem 'rails-i18n', '~> 5.0.4'
gem 'seed-fu', '~> 2.3.7'
gem 'sqlite3'
gem 'deep_cloneable', '~> 2.2.2'
gem 'airbrake', '~> 5.0'
gem 'database_cleaner'

group :metrics do
gem 'brakeman'
Expand Down Expand Up @@ -51,4 +49,4 @@ group :test do
gem 'simplecov', '~> 0.12.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
4 changes: 1 addition & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

Expand All @@ -10,7 +8,7 @@ require 'rake/testtask'
Rails.application.load_tasks

Rake::TestTask.new(:test) do |t|
t.libs << %w(lib test)
t.libs << %w[lib test]
t.test_files = Dir['test/**/*_test.rb'].reject do |path|
path.include?('features')
end
Expand Down
2 changes: 0 additions & 2 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

module ApplicationCable
class Channel < ActionCable::Channel::Base
end
Expand Down
2 changes: 0 additions & 2 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

class ActivitiesController < PersonRelationsController
self.permitted_attrs = [:description, :role, :technology, :year_from, :year_to, :person_id]
self.permitted_attrs = %i[description role technology year_from year_to person_id]
end
4 changes: 1 addition & 3 deletions app/controllers/advanced_trainings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

class AdvancedTrainingsController < PersonRelationsController
self.permitted_attrs = [:description, :year_from, :year_to, :person_id]
self.permitted_attrs = %i[description year_from year_to person_id]
end
2 changes: 0 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

class ApplicationController < ActionController::API
before_action :authorize

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/authentication_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

require 'ldap_tools'

class AuthenticationController < ApplicationController
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/crud_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# A generic controller to display, create, update and destroy entries of a certain model class.
class CrudController < ListController
class_attribute :permitted_attrs, :nested_models
Expand Down Expand Up @@ -80,7 +78,7 @@ def model_params
attrs = map_relationships(attrs)
AttributeDeserializer.new(attrs, nested_models: nested_models).run
end

def map_relationships(attrs)
relationships = params[:data][:relationships]

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/dry_crud/searchable.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# The search functionality for the index table.
# Define an array of searchable string columns in your subclassing
# controllers using the class attribute +search_columns+.
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/educations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

class EducationsController < PersonRelationsController
self.permitted_attrs = [:location, :title, :year_from, :year_to, :person_id]
self.permitted_attrs = %i[location title year_from year_to person_id]
end
6 changes: 2 additions & 4 deletions app/controllers/expertise_categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# encoding: utf-8

class ExpertiseCategoriesController < CrudController
self.permitted_attrs = [:name, :discipline]
self.permitted_attrs = %i[name discipline]

self.nested_models = [:expertise_topic]
self.nested_models = %i[expertise_topic]

def fetch_entries
raise unless params[:discipline]
Expand Down
8 changes: 3 additions & 5 deletions app/controllers/expertise_topic_skill_values_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# encoding: utf-8

class ExpertiseTopicSkillValuesController < CrudController
self.permitted_attrs = [:years_of_experience, :number_of_projects, :last_use,
:skill_level, :comment, :expertise_topic_id, :person_id]
self.permitted_attrs = %i[years_of_experience number_of_projects last_use
skill_level comment expertise_topic_id person_id]

def create(options= {})
def create(options = {})
person_id = params[:data][:relationships][:person][:data][:id]
if person_id
raise 'not yet implemented' if Person.find(person_id).origin_person_id
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/expertise_topics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# encoding: utf-8

class ExpertiseTopicsController < CrudController
self.permitted_attrs = [:name, :user_topic, :expertise_category_id]
self.permitted_attrs = %i[name user_topic expertise_category_id]

self.nested_models = [:expertise_topic_skill_values]
self.nested_models = %i[expertise_topic_skill_values]

def fetch_entries
raise unless params[:category_id]
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/list_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# A generic controller to display entries of a certain model class.
class ListController < ApplicationController
delegate :model_class, :model_identifier, :model_serializer, :list_serializer,
Expand Down
20 changes: 9 additions & 11 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# encoding: utf-8

class PeopleController < CrudController
self.permitted_attrs = [:birthdate, :picture, :language, :location,
:martial_status, :updated_by, :name, :origin, :role, :title,
:competences, :status_id, :variation_name, :company]
self.permitted_attrs = %i[birthdate picture language location
martial_status updated_by name origin role title
competences status_id variation_name company]

self.nested_models = [:advanced_trainings, :activities, :projects,
:educations]
self.nested_models = %i[advanced_trainings activities projects
educations]

skip_before_action :authorize, only: [:picture]
skip_before_action :authorize, only: :picture

def index
people = fetch_entries
Expand All @@ -22,7 +20,7 @@ def show
end

def update_picture
person.update_attributes(picture: params[:picture])
person.update(picture: params[:picture])
render json: { data: { picture_path: person_picture_path(params[:person_id]) } }
end

Expand Down Expand Up @@ -102,15 +100,15 @@ def content_disposition_filename_ascii(filename)
'filename="' +
percent_escape(
I18n.transliterate(filename),
/[^ A-Za-z0-9!#$+.^_`|~-]/
/[^ A-Za-z0-9!#{$+}.^_`|~-]/
) + '"'
end

def content_disposition_filename_utf8(filename)
"filename*=UTF-8''" +
percent_escape(
filename,
/[^A-Za-z0-9!#$&+.^_`|~-]/
/[^A-Za-z0-9!#{$&}+.^_`|~-]/
)
end

Expand Down
2 changes: 0 additions & 2 deletions app/controllers/person_relations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

class PersonRelationsController < CrudController
def person_id
params['data']['relationships']['person']['data']['id']
Expand Down
6 changes: 2 additions & 4 deletions app/controllers/person_variations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# encoding: utf-8

class PersonVariationsController < CrudController
self.permitted_attrs = PeopleController.permitted_attrs + [:variation_name, :person_id]
self.permitted_attrs = PeopleController.permitted_attrs + %i[variation_name person_id]

self.nested_models = PeopleController.nested_models

Expand All @@ -17,7 +15,7 @@ def create
else
render json: variation.errors.details, status: :unprocessable_entity
end
rescue => e
rescue StandardError => e
render json: e.message, status: :unprocessable_entity
end

Expand Down
6 changes: 2 additions & 4 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# encoding: utf-8

class ProjectsController < PersonRelationsController
self.permitted_attrs = [:description, :title, :role, :technology,
:year_to, :year_from, :person_id]
self.permitted_attrs = %i[description title role technology
year_to year_from person_id]
end
2 changes: 0 additions & 2 deletions app/controllers/static_assets_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

class StaticAssetsController < ActionController::Base

protect_from_forgery with: :null_session
Expand Down
2 changes: 0 additions & 2 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# encoding: utf-8

class ApplicationJob < ActiveJob::Base
end
2 changes: 0 additions & 2 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

class ApplicationMailer < ActionMailer::Base
default from: '[email protected]'
layout 'mailer'
Expand Down
4 changes: 1 addition & 3 deletions app/models/activity.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# == Schema Information
#
# Table name: activities
Expand All @@ -19,7 +17,7 @@ class Activity < ApplicationRecord
belongs_to :person, touch: true

validates :year_from, :person_id, :role, presence: true
validates :year_from, :year_to, length: {is: 4}, allow_blank: true
validates :year_from, :year_to, length: { is: 4 }, allow_blank: true
validates :description, length: { maximum: 5000 }
validates :role, length: { maximum: 500 }
validate :year_from_before_year_to
Expand Down
4 changes: 1 addition & 3 deletions app/models/advanced_training.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

# == Schema Information
#
# Table name: advanced_trainings
Expand All @@ -18,7 +16,7 @@ class AdvancedTraining < ApplicationRecord
belongs_to :person, touch: true

validates :year_from, :person_id, :description, presence: true
validates :year_from, :year_to, length: {is: 4}, allow_blank: true
validates :year_from, :year_to, length: { is: 4 }, allow_blank: true
validates :description, length: { maximum: 5000 }
validate :year_from_before_year_to

Expand Down
2 changes: 0 additions & 2 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# encoding: utf-8

class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

Expand Down
4 changes: 2 additions & 2 deletions app/models/education.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: utf-8

# == Schema Information
#
# Table name: educations
Expand All @@ -17,7 +17,7 @@ class Education < ApplicationRecord
belongs_to :person, touch: true

validates :year_from, :person_id, :title, :location, presence: true
validates :year_from, :year_to, length: {is: 4}, allow_blank: true
validates :year_from, :year_to, length: { is: 4 }, allow_blank: true
validates :location, :title, length: { maximum: 500 }
validate :year_from_before_year_to

Expand Down
10 changes: 5 additions & 5 deletions app/models/expertise_category.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: utf-8

#
# == Schema Information
#
Expand All @@ -15,12 +15,12 @@ class ExpertiseCategory < ApplicationRecord
enum discipline: [:development, :system_engineering]

validates :discipline, presence: true
validates :name, presence: true,
uniqueness: { scope: :discipline },
validates :name, presence: true,
uniqueness: { scope: :discipline },
length: { maximum: 100 }

scope :list, -> (discipline = nil) do
where(discipline: discipline )
scope :list, ->(discipline = nil) do
where(discipline: discipline)
end

end
12 changes: 6 additions & 6 deletions app/models/expertise_topic.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# encoding: utf-8

#
# == Schema Information
#
Expand All @@ -14,14 +14,14 @@ class ExpertiseTopic < ApplicationRecord
belongs_to :expertise_category
has_many :expertise_topic_skill_values, dependent: :destroy

validates :name, presence: true,
length: { maximum: 100 },
validates :name, presence: true,
length: { maximum: 100 },
uniqueness: { scope: :expertise_category }

scope :list, -> (category_id= nil) do
scope :list, ->(category_id = nil) do
includes(:expertise_category, :expertise_topic_skill_values).
where(expertise_categories: { id: category_id } ).
where(user_topic: false)
where(expertise_categories: { id: category_id }).
where(user_topic: false)
end

end
Loading

0 comments on commit 6643caf

Please sign in to comment.