Skip to content

Commit

Permalink
Merge pull request #12 from the-teacher/rubocop
Browse files Browse the repository at this point in the history
Add Rubocop
  • Loading branch information
the-teacher authored Jan 29, 2023
2 parents ce1573c + 71ef225 commit 1265064
Show file tree
Hide file tree
Showing 64 changed files with 360 additions and 130 deletions.
70 changes: 70 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require: rubocop-rails
Style/FrozenStringLiteralComment:
Enabled: true
Style/Documentation:
Enabled: false
Style/StringLiterals:
Exclude:
- Gemfile
- Rakefile
- test/test_helper.rb
- config/boot.rb
- config/importmap.rb
- config/application.rb
- config/initializers/assets.rb
- config/environments/test.rb
- config/environments/development.rb
- config/environments/production.rb
- app/mailers/application_mailer.rb
Naming/FileName:
Exclude:
- config/_PUMA.rb
- config/_SCHEDULE.rb
- config/initializers/_CHEWY.rb
- config/initializers/_CONFIG.rb
- config/initializers/_REDIS.rb
- config/initializers/_SIDEKIQ.rb
Style/SymbolArray:
Exclude:
- config/initializers/filter_parameter_logging.rb
Style/GlobalStdStream:
Exclude:
- config/environments/production.rb
Style/ClassAndModuleChildren:
Exclude:
- test/test_helper.rb
Layout/SpaceInsidePercentLiteralDelimiters:
Exclude:
- Gemfile
Rails/Output:
Exclude:
- db/seeds.rb
- app/jobs/example_job.rb
- app/models/currency_rate.rb
- config/environments/development.rb
- config/initializers/_CHEWY.rb
- config/initializers/_CONFIG.rb
- config/initializers/_REDIS.rb
- config/initializers/_SIDEKIQ.rb
Metrics/MethodLength:
Exclude:
- bin/helpers/docker.rb
- app/controllers/demo_controller.rb
Style/OptionalBooleanParameter:
Exclude:
- bin/helpers/docker.rb
Style/OptionalBooleanParameter:
Exclude:
- bin/helpers/common.rb
Lint/UselessAssignment:
Exclude:
- bin/helpers/puma.rb
- bin/helpers/sidekiq.rb
Style/GlobalVars:
Exclude:
- bin/helpers/common.rb
- bin/helpers/helpers.rb
- config/initializers/_REDIS.rb
Metrics/BlockLength:
Exclude:
- config/environments/development.rb
7 changes: 6 additions & 1 deletion 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 @@ -44,8 +46,11 @@ gem "kaminari", "1.2.2"
gem "whenever", "1.0.0", require: false

group :development, :test do
# fake data for development and testing
# Fake data for development and testing
gem "faker", "3.1.0"

# Code linting
gem "rubocop-rails", "2.17.4", require: false
end

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
27 changes: 25 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
bindex (0.8.1)
bootsnap (1.15.0)
msgpack (~> 1.2)
Expand Down Expand Up @@ -177,6 +178,7 @@ GEM
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
json (2.6.3)
kaminari (1.2.2)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.2.2)
Expand Down Expand Up @@ -219,6 +221,9 @@ GEM
nokogiri (1.13.10)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
parallel (1.22.1)
parser (3.2.0.0)
ast (~> 2.4.1)
pg (1.4.5)
public_suffix (5.0.1)
puma (5.6.5)
Expand Down Expand Up @@ -253,13 +258,31 @@ GEM
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rainbow (3.1.1)
rake (13.0.6)
redis (5.0.5)
redis-client (>= 0.9.0)
redis-client (0.11.2)
connection_pool
regexp_parser (2.6.1)
rexml (3.2.5)
rubocop (1.44.1)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.24.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.24.1)
parser (>= 3.1.1.0)
rubocop-rails (2.17.4)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
sanitize (6.0.0)
Expand Down Expand Up @@ -291,8 +314,7 @@ GEM
railties (>= 6.0.0)
tzinfo (2.0.5)
concurrent-ruby (~> 1.0)
tzinfo-data (1.2022.7)
tzinfo (>= 1.0.0)
unicode-display_width (2.4.2)
web-console (4.2.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -329,6 +351,7 @@ DEPENDENCIES
puma (= 5.6.5)
rails (= 7.0.4.2)
redis (= 5.0.5)
rubocop-rails (= 2.17.4)
sanitize (= 6.0.0)
selenium-webdriver (= 4.7.1)
sidekiq (= 7.0.2)
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ Rails 7 Application is Ready in Minutes!
<td><b><a href="https://www.ruby-toolbox.com/categories/web_servers">Puma</a></b></td>
<td>Application Web Server. To launch Rails app</td>
</tr>
<tr>
<td colspan="3"><b>Code Quality</b></td>
</tr>
<tr>
<td><img width="100px" alt="rspec" src="docs/rubocop.png"></td>
<td><b><a href="https://www.ruby-toolbox.com/categories/code_metrics">Rubocop</a></b></td>
<td>Ruby static code analyzer (a.k.a. linter) and formatter.</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -144,11 +152,6 @@ What I'm going to add...
<td><b><a href="https://www.ruby-toolbox.com/categories/testing_frameworks">RSpec</a></b></td>
<td>Testing Framework for Rails</td>
</tr>
<tr>
<td><img width="100px" alt="rspec" src="docs/rubocop.png"></td>
<td><b><a href="https://www.ruby-toolbox.com/categories/code_metrics">Rubocop</a></b></td>
<td>Ruby static code analyzer (a.k.a. linter) and formatter.</td>
</tr>
</tbody>
</table>

Expand Down Expand Up @@ -195,13 +198,14 @@ What was done:
4. Launching PgSQL Container
5. Launching Redis Container
6. Launching Rails Container
7. Installing Gems. Please Wait
7. Installing Gems
8. Create DB. Migrate DB. Create Seeds
9. Indexing Article Model
10. Launching Rails App with Puma
11. Launching Sidekiq
12. Visit Rails App: http://localhost:3000
13. Visit Mail Service: http://localhost:1080
12. Rubocop is Checking
13. Visit Rails App: http://localhost:3000
14. Visit Mail Service: http://localhost:1080
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Welcome to RAILS 7!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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/chewy/articles_index.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# @articles = ArticlesIndex.query(
# query_string: {
# query: 'Article',
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
end
17 changes: 10 additions & 7 deletions app/controllers/demo_controller.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# frozen_string_literal: true

class DemoController < ApplicationController
def index
# Example of ElasticSearch/Chewy search
@search_query = params[:search] || 'Article'
@found_articles = ArticlesIndex
.query(
query_string: {
query: @search_query,
fields: [:title, :content]
})
.per(3)
.page params[:page]
.query(
query_string: {
query: @search_query,
fields: %i[title content]
}
)
.per(3)
.page params[:page]

@articles = Article.order(:title).page params[:page]
end
Expand Down
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
2 changes: 2 additions & 0 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# frozen_string_literal: true

module ArticlesHelper
end
2 changes: 2 additions & 0 deletions app/jobs/application_job.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
Expand Down
8 changes: 5 additions & 3 deletions app/jobs/example_job.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# frozen_string_literal: true

class ExampleJob < ApplicationJob
queue_as :default

# ExampleJob.perform_now
# ExampleJob.perform_later
# ExampleJob.set(wait: 1.week).perform_later()
def perform(*args)
puts "Job is Started"
def perform(*_args)
puts 'Job is Started'
sleep(10)
puts "Job is Finished"
puts 'Job is Finished'
end
end
2 changes: 2 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
Expand Down
4 changes: 3 additions & 1 deletion app/mailers/demo_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# rails generate mailer demo
#
# DemoMailer.welcome_email.deliver!
Expand All @@ -6,7 +8,7 @@ class DemoMailer < ApplicationMailer

def welcome_email
mail(
to: "test@test.com",
to: 'test@test.com',
subject: 'Welcome to Rails 7. StartKit'
)
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationRecord < ActiveRecord::Base
primary_abstract_class
end
2 changes: 2 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# rails g model Article
# title:string
# content_raw:text
Expand Down
10 changes: 6 additions & 4 deletions app/models/currency_rate.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# rails g model currency_rate
# from:string
# to:string
Expand All @@ -8,20 +10,20 @@
# rails runner "CurrencyRate.get('USD', 'EUR')"

class CurrencyRate < ApplicationRecord
API = "https://api.exchangerate.host/latest"
API = 'https://api.exchangerate.host/latest'

def self.get(from = "USD", to = "EUR")
def self.get(from = 'USD', to = 'EUR')
uri = URI(CurrencyRate::API + "?base=#{from}&symbols=#{to}")

response = Net::HTTP.get(uri)
response_obj = JSON.parse(response)

create!(
from: from, to: to,
from:, to:,
rate: response_obj['rates'][to]
)

puts "[#{DateTime.now.strftime('%d.%m.%Y %H.%M.%S')}]: " + \
puts "[#{DateTime.now.strftime('%d.%m.%Y %H.%M.%S')}]: " \
"#{from}:#{to} currency rate: " + response_obj['rates'][to].to_s
end
end
9 changes: 3 additions & 6 deletions bin/helpers/chewy.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
def chewy_index
puts "Indexing with CHEWY"
container_exec('rails', 'rake chewy:update')
end
# frozen_string_literal: true

def chewy_index
puts "Indexing with CHEWY"
puts 'Indexing with CHEWY'
container_exec('rails', 'rake chewy:update')
end

def chewy_reset
puts "Dropping CHEWY indicies"
puts 'Dropping CHEWY indicies'
container_exec('rails', 'rake chewy:reset')
end
Loading

0 comments on commit 1265064

Please sign in to comment.