Skip to content

Commit

Permalink
Feature rubocop integration + YARD documentation (brotandgames#20)
Browse files Browse the repository at this point in the history
* Initial setup for Rubocop

* Rubocop fix: Style/ClassAndModuleChildren

* Rubocop fix: Style/GuardClause

* Rubocop fix: Metrics/LineLength

* Generate YARD documentation

* Add rubocop checks to Travis CI

* Rubocop fix: Lint/IneffectiveAccessModifier

* Fix production.rb

* Update description of status.
  • Loading branch information
tareksamni authored and brotandgames committed Jul 29, 2019
1 parent 63387fd commit afdbf8a
Show file tree
Hide file tree
Showing 106 changed files with 7,485 additions and 240 deletions.
16 changes: 16 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
inherit_from: .rubocop_todo.yml

Metrics/AbcSize:
Max: 40

Metrics/BlockLength:
Max: 300

Metrics/CyclomaticComplexity:
Max: 10

Metrics/MethodLength:
Max: 35

Metrics/PerceivedComplexity:
Max: 10
32 changes: 32 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-07-27 10:16:20 +0100 using RuboCop version 0.73.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: 1
Lint/UriEscapeUnescape:
Exclude:
- 'app/validators/http_url_validator.rb'

# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
AllowURI: true
IgnoredPatterns: [".*#.*"] # ignore lines with comments
AllowHeredoc: true
Exclude:
- 'config/**/*'
- 'db/**/*'
- 'bin/**/*'

Style/Documentation:
Exclude:
- 'db/migrate/*'
- 'test/test_helper.rb'
- 'app/**/*'
- 'config/application.rb'
- 'test/**/*'
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ before_install:
- gem install bundler -v 2.0.1
script:
- yarn install --check-files
- bundle exec rubocop
- bundle exec rake
13 changes: 13 additions & 0 deletions .yardoc/checksums
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
app/models/check.rb 40bf0311001002af511a066cad10a3cc6180b25f
app/jobs/application_job.rb 5755649620a15b1905ff6a343b2604e7bf8fee8d
app/mailers/check_mailer.rb 32b55235d0ffc146c86542ee9ee8a9cfaf3557cc
app/helpers/checks_helper.rb 2efa87ee9f98071c66033b8f9f895469286d2b4d
app/models/application_record.rb 73507b0608fcd792376697d4b0bb8e25f63e1f3d
app/validators/cron_validator.rb 2c879712ce9865014cc189f07d6a68f4713de1d6
app/helpers/application_helper.rb d0cfecb4c6d765c36684c31822818580eb5c3bdc
app/mailers/application_mailer.rb 42cfb76a486b0b17dd0a8a6b6733c8cb8babd623
app/controllers/checks_controller.rb da04219bc3ad7a7a221e0cda0ac6543c69a80fd9
app/validators/http_url_validator.rb 786ec99fef4d50adeeb29b6c81cde724a5ab4464
app/channels/application_cable/channel.rb c37215169051d5564efe41d08f06c645e223bf34
app/controllers/application_controller.rb 2045a4a289f66e2e093494be16d8003b24923b31
app/channels/application_cable/connection.rb 52c7ca2b443ed5fa642c79092910af60ff882cf9
Empty file added .yardoc/complete
Empty file.
Binary file added .yardoc/object_types
Binary file not shown.
Binary file added .yardoc/objects/root.dat
Binary file not shown.
Binary file added .yardoc/proxy_types
Binary file not shown.
19 changes: 13 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

Expand Down Expand Up @@ -30,17 +32,18 @@ gem 'bootsnap', '>= 1.4.2', require: false

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'byebug', platforms: %i[mri mingw x64_mingw]
end

group :development do
gem 'letter_opener'
gem 'listen', '>= 3.0.5', '< 3.2'
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
gem "letter_opener"
gem 'yard'
end

group :test do
Expand All @@ -51,10 +54,14 @@ group :test do
gem 'webdrivers'
end

group :development, :test do
gem 'rubocop'
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]

gem 'simple_form'
gem 'bootstrap', '~> 4.3.1'
gem 'tabler-rubygem'
gem 'rufus-scheduler'
gem 'simple_form'
gem 'tabler-rubygem'
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ GEM
zeitwerk (~> 2.1, >= 2.1.4)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
ast (2.4.0)
autoprefixer-rails (9.5.1.1)
execjs
bindex (0.7.0)
Expand Down Expand Up @@ -93,6 +94,7 @@ GEM
activesupport (>= 4.2.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.3)
jbuilder (2.8.0)
activesupport (>= 4.2.0)
multi_json (>= 1.2)
Expand Down Expand Up @@ -121,6 +123,9 @@ GEM
nio4r (2.3.1)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
parallel (1.17.0)
parser (2.6.3.0)
ast (~> 2.4.0)
popper_js (1.14.5)
public_suffix (3.0.3)
puma (3.12.1)
Expand Down Expand Up @@ -156,11 +161,20 @@ GEM
method_source
rake (>= 0.8.7)
thor (>= 0.20.3, < 2.0)
rainbow (3.0.0)
rake (12.3.2)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
regexp_parser (1.4.0)
rubocop (0.73.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.6)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
ruby_dep (1.5.0)
rubyzip (1.2.2)
rufus-scheduler (3.6.0)
Expand Down Expand Up @@ -214,6 +228,7 @@ GEM
turbolinks-source (5.2.0)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.6.0)
web-console (4.0.0)
actionview (>= 6.0.0.a)
activemodel (>= 6.0.0.a)
Expand All @@ -232,6 +247,7 @@ GEM
websocket-extensions (0.1.3)
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.20)
zeitwerk (2.1.6)

PLATFORMS
Expand All @@ -247,6 +263,7 @@ DEPENDENCIES
listen (>= 3.0.5, < 3.2)
puma (~> 3.11)
rails (~> 6.0.0.rc1)
rubocop
rufus-scheduler
sass-rails (~> 5)
selenium-webdriver
Expand All @@ -260,6 +277,7 @@ DEPENDENCIES
web-console (>= 3.3.0)
webdrivers
webpacker (~> 4.0)
yard

RUBY VERSION
ruby 2.6.3p62
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# 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 Down
2 changes: 2 additions & 0 deletions app/channels/application_cable/channel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

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

module ApplicationCable
class Connection < ActionCable::Connection::Base
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
protect_from_forgery unless: -> { request.format.json? }
end
61 changes: 38 additions & 23 deletions app/controllers/checks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

class ChecksController < ApplicationController
before_action :set_check, only: [:show, :edit, :update, :destroy]
before_action :set_check, only: %i[show edit update destroy]

# GET /checks
# GET /checks.json
Expand All @@ -9,17 +11,15 @@ def index

# GET /checks/1
# GET /checks/1.json
def show
end
def show; end

# GET /checks/new
def new
@check = Check.new
end

# GET /checks/1/edit
def edit
end
def edit; end

# POST /checks
# POST /checks.json
Expand All @@ -28,11 +28,15 @@ def create

respond_to do |format|
if @check.save
format.html { redirect_to @check, notice: 'Check was successfully created.' }
format.html do
redirect_to @check, notice: 'Check was successfully created.'
end
format.json { render :show, status: :created, location: @check }
else
format.html { render :new }
format.json { render json: @check.errors, status: :unprocessable_entity }
format.json do
render json: @check.errors, status: :unprocessable_entity
end
end
end
end
Expand All @@ -42,11 +46,15 @@ def create
def update
respond_to do |format|
if @check.update(check_params)
format.html { redirect_to @check, notice: 'Check was successfully updated.' }
format.html do
redirect_to @check, notice: 'Check was successfully updated.'
end
format.json { render :show, status: :ok, location: @check }
else
format.html { render :edit }
format.json { render json: @check.errors, status: :unprocessable_entity }
format.json do
render json: @check.errors, status: :unprocessable_entity
end
end
end
end
Expand All @@ -56,7 +64,9 @@ def update
def destroy
@check.destroy
respond_to do |format|
format.html { redirect_to checks_url, notice: 'Check was successfully destroyed.' }
format.html do
redirect_to checks_url, notice: 'Check was successfully destroyed.'
end
format.json { head :no_content }
end
end
Expand All @@ -78,7 +88,7 @@ def job
format.json { render :job, status: :ok }
else
format.html { render :job, status: 404 }
format.json { render json: "Job not found", status: 404 }
format.json { render json: 'Job not found', status: 404 }
end
end
end
Expand All @@ -92,23 +102,28 @@ def jobs_recreate
end
Rails.logger.info "ciao-scheduler Database conn. pool stat: #{ActiveRecord::Base.connection_pool.stat}"
respond_to do |format|
format.html { redirect_to checks_url, notice: 'Check jobs were successfully recreated.' }
format.json { render json: "Check jobs were successfully recreated.", status: 200 }
format.html do
redirect_to checks_url,
notice: 'Check jobs were successfully recreated.'
end
format.json do
render json: 'Check jobs were successfully recreated.', status: 200
end
end
end

# GET /checks/admin
def admin
end
def admin; end

private
# Use callbacks to share common setup or constraints between actions.
def set_check
@check = Check.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def check_params
params.require(:check).permit(:name, :cron, :url, :active)
end
# Use callbacks to share common setup or constraints between actions.
def set_check
@check = Check.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def check_params
params.require(:check).permit(:name, :cron, :url, :active)
end
end
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module ApplicationHelper
end
Loading

0 comments on commit afdbf8a

Please sign in to comment.