Skip to content

Commit

Permalink
Corrects Style/StringLiterals and Style/StringLiteralsInInterpolation…
Browse files Browse the repository at this point in the history
… offenses

Sets the EnforcedStyle to `double_quotes` because this makes much more sense than the default. See rubocop/rubocop#5306
  • Loading branch information
benlangfeld committed Dec 5, 2018
1 parent 1b26c8e commit 654bb94
Show file tree
Hide file tree
Showing 35 changed files with 293 additions and 303 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ Metrics/BlockLength:
Exclude:
- '**/spec_helper.rb'
- '**/**_spec.rb'

# Single quotes being faster is hardly measurable and only affects parse time.
# Enforcing double quotes reduces the times where you need to change them when introducing an interpolation.
# Use single quotes only if their semantics are needed.
Style/StringLiterals:
EnforcedStyle: double_quotes
18 changes: 1 addition & 17 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-12-03 15:33:57 +0000 using RuboCop version 0.60.0.
# on 2018-12-05 20:15:45 +0000 using RuboCop version 0.60.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
Expand Down Expand Up @@ -542,22 +542,6 @@ Style/SpecialGlobalVars:
- 'message_bus.gemspec'
- 'spec/spec_helper.rb'

# Offense count: 657
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
Exclude:
- 'examples/chat/chat.rb'
- 'lib/message_bus/rack/diagnostics.rb'

# Offense count: 1
Style/StructInheritance:
Exclude:
Expand Down
24 changes: 12 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in message_bus.gemspec
gemspec

group :test do
gem 'minitest'
gem 'minitest-hooks'
gem 'rake'
gem 'http_parser.rb'
gem 'thin'
gem 'rack-test', require: 'rack/test'
gem 'jasmine'
gem "minitest"
gem "minitest-hooks"
gem "rake"
gem "http_parser.rb"
gem "thin"
gem "rack-test", require: "rack/test"
gem "jasmine"
end

gem 'rack'
gem 'concurrent-ruby' # for distributed-cache
gem "rack"
gem "concurrent-ruby" # for distributed-cache

gem 'rubocop'
gem 'yard'
gem "rubocop"
gem "yard"
32 changes: 16 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require 'rubygems'
require 'rake/testtask'
require 'bundler'
require 'bundler/gem_tasks'
require 'bundler/setup'
require 'jasmine'
require "rubygems"
require "rake/testtask"
require "bundler"
require "bundler/gem_tasks"
require "bundler/setup"
require "jasmine"

ENV['JASMINE_CONFIG_PATH'] ||= File.join(Dir.pwd, 'spec', 'assets', 'support', 'jasmine.yml')
load 'jasmine/tasks/jasmine.rake'
ENV["JASMINE_CONFIG_PATH"] ||= File.join(Dir.pwd, "spec", "assets", "support", "jasmine.yml")
load "jasmine/tasks/jasmine.rake"

require 'rubocop/rake_task'
require "rubocop/rake_task"
RuboCop::RakeTask.new

require 'yard'
require "yard"
YARD::Rake::YardocTask.new

desc "Generate documentation for Yard, and fail if there are any warnings"
Expand All @@ -38,25 +38,25 @@ end

run_spec = proc do |backend|
begin
ENV['MESSAGE_BUS_BACKEND'] = backend
ENV["MESSAGE_BUS_BACKEND"] = backend
sh "#{FileUtils::RUBY} -e \"ARGV.each{|f| load f}\" #{Dir['spec/**/*_spec.rb'].to_a.join(' ')}"
ensure
ENV.delete('MESSAGE_BUS_BACKEND')
ENV.delete("MESSAGE_BUS_BACKEND")
end
end

task spec: [:spec_memory, :spec_redis, :spec_postgres, :spec_client_js, :rubocop, :test_doc]

task spec_client_js: 'jasmine:ci'
task spec_client_js: "jasmine:ci"

task :spec_redis do
run_spec.call('redis')
run_spec.call("redis")
end

task :spec_memory do
run_spec.call('memory')
run_spec.call("memory")
end

task :spec_postgres do
run_spec.call('postgres')
run_spec.call("postgres")
end
6 changes: 3 additions & 3 deletions examples/bench/config.ru
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
$LOAD_PATH.unshift File.expand_path("../../../lib", __FILE__)

require 'message_bus'
require 'stackprof'
require "message_bus"
require "stackprof"

if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
Expand Down
2 changes: 1 addition & 1 deletion examples/bench/puma.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'message_bus'
require "message_bus"
on_worker_boot do
MessageBus.after_fork
end
2 changes: 1 addition & 1 deletion examples/bench/unicorn.conf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'message_bus'
require "message_bus"
after_fork do |_server, _worker|
MessageBus.after_fork
end
6 changes: 3 additions & 3 deletions examples/chat/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
gem 'puma'
gem 'redis'
gem 'sinatra'
gem "puma"
gem "redis"
gem "sinatra"
32 changes: 16 additions & 16 deletions examples/chat/chat.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
require 'message_bus'
require 'sinatra'
require 'sinatra/base'
require 'set'
require 'json'
$LOAD_PATH.unshift File.expand_path("../../../lib", __FILE__)
require "message_bus"
require "sinatra"
require "sinatra/base"
require "set"
require "json"

$online = Hash.new

Expand All @@ -17,7 +17,7 @@
end

MessageBus.user_id_lookup do |env|
MessageBus.logger = env['rack.logger']
MessageBus.logger = env["rack.logger"]
name = env["HTTP_X_NAME"]
if name
unless $online[name]
Expand Down Expand Up @@ -47,34 +47,34 @@ def expire_old_sessions
end

class Chat < Sinatra::Base
set :public_folder, File.expand_path('../../../assets', __FILE__)
set :public_folder, File.expand_path("../../../assets", __FILE__)

use MessageBus::Rack::Middleware

post '/enter' do
post "/enter" do
name = params["name"]
i = 1
while $online.include? name
name = "#{params["name"]}#{i}"
name = "#{params['name']}#{i}"
i += 1
end
MessageBus.publish '/presence', enter: name
MessageBus.publish "/presence", enter: name
{ users: $online.keys, name: name }.to_json
end

post '/leave' do
post "/leave" do
# puts "Got leave for #{params["name"]}"
MessageBus.publish '/presence', leave: params["name"]
MessageBus.publish "/presence", leave: params["name"]
end

post '/message' do
post "/message" do
msg = { data: params["data"][0..500], name: params["name"][0..100] }
MessageBus.publish '/message', msg
MessageBus.publish "/message", msg

"OK"
end

get '/' do
get "/" do
<<~HTML
<html>
Expand Down
2 changes: 1 addition & 1 deletion examples/chat/config.ru
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require './chat'
require "./chat"
run Chat
4 changes: 2 additions & 2 deletions examples/minimal/Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gem 'message_bus'
gem "message_bus"
2 changes: 1 addition & 1 deletion examples/minimal/config.ru
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'message_bus'
require "message_bus"

# MessageBus.long_polling_interval = 1000 * 2

Expand Down
12 changes: 6 additions & 6 deletions lib/message_bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# we still need to take care of the logger
if defined?(::Rails)
require 'message_bus/rails/railtie'
require "message_bus/rails/railtie"
end

# @see MessageBus::Implementation
Expand Down Expand Up @@ -64,7 +64,7 @@ def logger=(logger)
def logger
return @config[:logger] if @config[:logger]

require 'logger'
require "logger"
logger = Logger.new(STDOUT)
logger.level = Logger::INFO
configure(logger: logger)
Expand Down Expand Up @@ -574,7 +574,7 @@ def decode_channel_name(channel)
end

def global?(channel)
channel && channel.start_with?('/global/'.freeze)
channel && channel.start_with?("/global/".freeze)
end

def decode_message!(msg)
Expand Down Expand Up @@ -692,17 +692,17 @@ def new_subscriber_thread

# do the best we can to terminate self cleanly
fork do
Process.kill('TERM', pid)
Process.kill("TERM", pid)
sleep 10
begin
Process.kill('KILL', pid)
Process.kill("KILL", pid)
rescue Errno::ESRCH
logger.warn "#{Process.pid} successfully terminated by `TERM` signal."
end
end

sleep 10
Process.kill('KILL', pid)
Process.kill("KILL", pid)

else
timer.queue(keepalive_interval, &blk) if keepalive_interval > MIN_KEEPALIVE
Expand Down
Loading

0 comments on commit 654bb94

Please sign in to comment.