Skip to content

Commit

Permalink
Rubocop cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
wclittle committed Jan 15, 2021
1 parent 6674db6 commit 9ed99d8
Show file tree
Hide file tree
Showing 53 changed files with 380 additions and 172 deletions.
17 changes: 11 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 @@ -27,14 +29,15 @@ 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
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
gem 'web-console', '>= 3.3.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'annotate'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
Expand All @@ -48,12 +51,14 @@ group :test do
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 "stimulus_reflex", "~> 3.4"
gem 'stimulus_reflex', '~> 3.4'

gem "redis", "~> 4.2"
gem 'redis', '~> 4.2'

gem "react-rails", "~> 2.6"
gem 'react-rails', '~> 2.6'

gem 'turbo-rails'

gem 'rubocop', require: false
24 changes: 24 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ GEM
zeitwerk (~> 2.3)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
annotate (3.1.1)
activerecord (>= 3.2, < 7.0)
rake (>= 10.4, < 14.0)
ast (2.4.1)
babel-source (5.8.35)
babel-transpiler (0.7.0)
babel-source (>= 4.0, < 6)
Expand Down Expand Up @@ -114,6 +118,9 @@ GEM
nokogiri (1.11.1)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
parallel (1.20.1)
parser (3.0.0.0)
ast (~> 2.4.1)
pg (1.2.3)
public_suffix (4.0.6)
puma (4.3.7)
Expand Down Expand Up @@ -150,6 +157,7 @@ GEM
method_source
rake (>= 0.8.7)
thor (~> 1.0)
rainbow (3.0.0)
rake (13.0.3)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
Expand All @@ -162,6 +170,19 @@ GEM
tilt
redis (4.2.5)
regexp_parser (1.8.2)
rexml (3.2.4)
rubocop (1.8.1)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.2.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.4.0)
parser (>= 2.7.1.5)
ruby-progressbar (1.11.0)
rubyzip (2.3.0)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
Expand Down Expand Up @@ -199,6 +220,7 @@ GEM
rails (>= 6.0.0)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.0.0)
web-console (4.1.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand All @@ -223,6 +245,7 @@ PLATFORMS
ruby

DEPENDENCIES
annotate
bootsnap (>= 1.4.2)
byebug
capybara (>= 2.15)
Expand All @@ -233,6 +256,7 @@ DEPENDENCIES
rails (~> 6.1.1)
react-rails (~> 2.6)
redis (~> 4.2)
rubocop
sass-rails (>= 6)
selenium-webdriver
spring
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
3 changes: 3 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

module ApplicationCable
# Top-level methods for web socket connections
class Connection < ActionCable::Connection::Base
identified_by :session_id

Expand Down
5 changes: 4 additions & 1 deletion app/channels/hello_quotes_channel.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

# Web socket channel for our example app
class HelloQuotesChannel < ApplicationCable::Channel
def subscribed
stream_from "hello_quotes"
stream_from 'hello_quotes'
end
end
45 changes: 27 additions & 18 deletions app/controllers/api/v1/quotes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
class Api::V1::QuotesController < ApplicationController
include CableReady::Broadcaster
def index
respond_to do |format|
format.json { render json: Quote.order(created_at: :desc).all }
# frozen_string_literal: true

module Api
module V1
# Quotes API controller for our example app
class QuotesController < ApplicationController
include CableReady::Broadcaster
def index
respond_to do |format|
format.json { render json: Quote.order(created_at: :desc).all }
end
end

def create
quote = Quote.create(content: params[:content], author_name: params[:author])
respond_to do |format|
format.json { render json: quote }
end
end

def destroy
Quote.find(params[:id]).destroy
respond_to do |format|
format.json { render json: params[:id] }
end
end
end
end
def create
quote = Quote.create(content: params[:content], author_name: params[:author])
respond_to do |format|
format.json { render json: quote }
end
end
def destroy
Quote.find(params[:id]).destroy
respond_to do |format|
format.json { render json: params[:id] }
end
end
end
end
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/welcome_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# frozen_string_literal: true

# For our home page and public-facing marketing pages, terms, privacy, etc...
class WelcomeController < ApplicationController
include CableReady::Broadcaster
include CableReady::Broadcaster

def index
@quote = Quote.new
Expand All @@ -9,16 +12,16 @@ def index
def turbo_quotes
@quote = Quote.new
@quotes = Quote.all.order(created_at: :desc)
@prefix = "turbo-"
@prefix = 'turbo-'
end

def create_quote
Quote.create(quote_params)
def create_quote
Quote.create(quote_params)
end

private
private

def quote_params
params.require(:quote).permit(:content, :author_name)
end
end
end
end
3 changes: 3 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# frozen_string_literal: true

# For top level view helper methods
module ApplicationHelper
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
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
3 changes: 3 additions & 0 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# frozen_string_literal: true

# Constants and methods for all models
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
66 changes: 38 additions & 28 deletions app/models/quote.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
class Quote < ApplicationRecord
include CableReady::Broadcaster
after_create_commit -> {
# frozen_string_literal: true

# == Schema Information
#
# Table name: quotes
#
# id :bigint not null, primary key
# author_name :string
# content :text
# created_at :datetime not null
# updated_at :datetime not null
#
class Quote < ApplicationRecord
include CableReady::Broadcaster
after_create_commit lambda {
cable_ready['hello_quotes'].insert_adjacent_html(
selector: '#quotes_list',
position: 'afterBegin',
html: ApplicationController.new.render_to_string(partial: 'welcome/quote.html.erb', locals: {quote: self, prefix: nil})
html: ApplicationController.new.render_to_string(partial: 'welcome/quote.html.erb',
locals: { quote: self, prefix: nil })
).broadcast

ActionCable.server.broadcast("hello_quotes", {
type: "RQA::CreateQuoteSuccess",
response: {
entities: {
quotes: {
"#{id}": self
}
},
result: id
}
}
)

broadcast_prepend_to 'hello_turbo', target: "quotes_list_turbo", partial: "welcome/quote", locals: { prefix: "turbo-" }
ActionCable.server.broadcast('hello_quotes', {
type: 'RQA::CreateQuoteSuccess',
response: {
entities: {
quotes: {
"#{id}": self
}
},
result: id
}
})

broadcast_prepend_to 'hello_turbo', target: 'quotes_list_turbo', partial: 'welcome/quote',
locals: { prefix: 'turbo-' }
}

after_destroy_commit -> {
after_destroy_commit lambda {
cable_ready['hello_quotes'].remove(
selector: "#quote-#{id}"
).remove(
selector: "#turbo-quote-#{id}"
).broadcast
ActionCable.server.broadcast("hello_quotes", {
type: "RQA::DeleteQuoteSuccess",
response: {
data: id.to_i
}
}
)
).broadcast
ActionCable.server.broadcast('hello_quotes', {
type: 'RQA::DeleteQuoteSuccess',
response: {
data: id.to_i
}
})
}
end
end
9 changes: 6 additions & 3 deletions app/reflexes/quotes_reflex.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

# Reflex methods for our example app
class QuotesReflex < StimulusReflex::Reflex
def destroy
def destroy
id = element.dataset[:id]
Quote.find(id).destroy
morph :nothing
Quote.find(id).destroy
morph :nothing
end
end
Loading

0 comments on commit 9ed99d8

Please sign in to comment.