Skip to content

Commit 2ff46bd

Browse files
committed
Runs safe auto correct on all files
1 parent f67d4e6 commit 2ff46bd

26 files changed

+856
-824
lines changed

Gemfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
source "http://rubygems.org"
1+
# frozen_string_literal: true
2+
3+
source 'http://rubygems.org'
24

35
gemspec
46

5-
gem "rake"
7+
gem 'rake'

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
# frozen_string_literal: true
2+
13
$LOAD_PATH.unshift 'lib'

lib/queue_bus/adapters/base.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module QueueBus
24
module Adapters
35
class Base
@@ -19,12 +21,12 @@ def redis
1921
raise NotImplementedError
2022
end
2123

22-
def enqueue(queue_name, klass, json)
24+
def enqueue(_queue_name, _klass, _json)
2325
# enqueue the given class (Driver/Rider) in your queue
2426
raise NotImplementedError
2527
end
2628

27-
def enqueue_at(epoch_seconds, queue_name, klass, json)
29+
def enqueue_at(_epoch_seconds, _queue_name, _klass, _json)
2830
# enqueue the given class (Publisher) in your queue to run at given time
2931
raise NotImplementedError
3032
end

lib/queue_bus/adapters/data.rb

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# a base adapter just for publishing and redis connection
24
module QueueBus
35
module Adapters
@@ -6,47 +8,46 @@ def enabled!
68
# nothing to do
79
end
810

9-
def redis=(client)
10-
@redis = client
11-
end
11+
attr_writer :redis
1212

1313
def redis(&block)
14-
raise "no redis instance set" unless @redis
14+
raise 'no redis instance set' unless @redis
15+
1516
block.call(@redis)
1617
end
1718

1819
def enqueue(queue_name, klass, json)
19-
push(queue_name, :class => klass.to_s, :args => [json])
20+
push(queue_name, class: klass.to_s, args: [json])
2021
end
2122

2223
def enqueue_at(epoch_seconds, queue_name, klass, json)
2324
item = delayed_job_to_hash_with_queue(queue_name, klass, [json])
2425
delayed_push(epoch_seconds, item)
2526
end
2627

27-
def setup_heartbeat!(queue_name)
28+
def setup_heartbeat!(_queue_name)
2829
raise NotImplementedError
2930
end
3031

3132
protected
3233

3334
def push(queue, item)
3435
watch_queue(queue)
35-
self.redis { |redis| redis.rpush "queue:#{queue}", ::QueueBus::Util.encode(item) }
36+
redis { |redis| redis.rpush "queue:#{queue}", ::QueueBus::Util.encode(item) }
3637
end
3738

3839
# Used internally to keep track of which queues we've created.
3940
# Don't call this directly.
4041
def watch_queue(queue)
41-
self.redis { |redis| redis.sadd(:queues, queue.to_s) }
42+
redis { |redis| redis.sadd(:queues, queue.to_s) }
4243
end
4344

4445
# Used internally to stuff the item into the schedule sorted list.
4546
# +timestamp+ can be either in seconds or a datetime object
4647
# Insertion if O(log(n)).
4748
# Returns true if it's the first job to be scheduled at that time, else false
4849
def delayed_push(timestamp, item)
49-
self.redis do |redis|
50+
redis do |redis|
5051
# First add this item to the list for this timestamp
5152
redis.rpush("delayed:#{timestamp.to_i}", ::QueueBus::Util.encode(item))
5253

@@ -56,9 +57,9 @@ def delayed_push(timestamp, item)
5657
redis.zadd :delayed_queue_schedule, timestamp.to_i, timestamp.to_i
5758
end
5859
end
59-
60+
6061
def delayed_job_to_hash_with_queue(queue, klass, args)
61-
{:class => klass.to_s, :args => args, :queue => queue}
62+
{ class: klass.to_s, args: args, queue: queue }
6263
end
6364
end
6465
end

lib/queue_bus/local.rb

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
# frozen_string_literal: true
2+
13
module QueueBus
24
# only process local queues
35
class Local
4-
56
class << self
67
def publish(attributes = {})
78
if ::QueueBus.local_mode == :suppress
89
::QueueBus.log_worker("Suppressed: #{attributes.inspect}")
9-
return # not doing anything
10+
return # not doing anything
1011
end
1112

1213
# To json and back to simlulate enqueueing
@@ -17,15 +18,15 @@ def publish(attributes = {})
1718

1819
# looking for subscriptions, not queues
1920
subscription_matches(attributes).each do |sub|
20-
bus_attr = { "bus_driven_at" => Time.now.to_i,
21-
"bus_rider_queue" => sub.queue_name,
22-
"bus_rider_app_key" => sub.app_key,
23-
"bus_rider_sub_key" => sub.key,
24-
"bus_rider_class_name" => sub.class_name}
21+
bus_attr = { 'bus_driven_at' => Time.now.to_i,
22+
'bus_rider_queue' => sub.queue_name,
23+
'bus_rider_app_key' => sub.app_key,
24+
'bus_rider_sub_key' => sub.key,
25+
'bus_rider_class_name' => sub.class_name }
2526
to_publish = bus_attr.merge(attributes || {})
2627
if ::QueueBus.local_mode == :standalone
2728
::QueueBus.enqueue_to(sub.queue_name, sub.class_name, bus_attr.merge(attributes || {}))
28-
else # defaults to inline mode
29+
else # defaults to inline mode
2930
sub.execute!(to_publish)
3031
end
3132
end
@@ -41,6 +42,5 @@ def subscription_matches(attributes)
4142
out
4243
end
4344
end
44-
4545
end
4646
end

lib/queue_bus/util.rb

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'multi_json'
24

35
module QueueBus
@@ -30,14 +32,14 @@ def decode(object)
3032
raise DecodeException, e.message, e.backtrace
3133
end
3234
end
33-
35+
3436
def underscore(camel_cased_word)
3537
word = camel_cased_word.to_s.dup
3638
word.gsub!('::', '/')
3739
# word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
38-
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
39-
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
40-
word.tr!("-", "_")
40+
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
41+
word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
42+
word.tr!('-', '_')
4143
word.downcase!
4244
word
4345
end
@@ -53,11 +55,11 @@ def camelize(term)
5355
# string = string.sub(/^[a-z\d]*/) { inflections.acronyms[$&] || $&.capitalize }
5456
string = string.sub(/^[a-z\d]*/) { $&.capitalize }
5557
# string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{inflections.acronyms[$2] || $2.capitalize}" }
56-
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
57-
string.gsub!(/\//, '::')
58+
string.gsub!(%r{(?:_|(/))([a-z\d]*)}i) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
59+
string.gsub!(%r{/}, '::')
5860
string
5961
end
60-
62+
6163
def constantize(camel_cased_word)
6264
names = camel_cased_word.split('::')
6365
names.shift if names.empty? || names.first.empty?
@@ -75,6 +77,7 @@ def constantize(camel_cased_word)
7577
constant = constant.ancestors.inject do |const, ancestor|
7678
break const if ancestor == Object
7779
break ancestor if ancestor.const_defined?(name, false)
80+
7881
const
7982
end
8083

@@ -84,4 +87,4 @@ def constantize(camel_cased_word)
8487
end
8588
end
8689
end
87-
end
90+
end

lib/queue_bus/version.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module QueueBus
2-
VERSION = "0.9.0"
4+
VERSION = '0.9.0'
35
end

lib/queue_bus/worker.rb

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
# frozen_string_literal: true
2+
13
module QueueBus
24
class Worker
3-
45
def self.perform(json)
56
klass = nil
67
attributes = ::QueueBus::Util.decode(json)
78
begin
8-
class_name = attributes["bus_class_proxy"]
9+
class_name = attributes['bus_class_proxy']
910
klass = ::QueueBus::Util.constantize(class_name)
1011
rescue NameError
1112
# not there anymore

queue-bus.gemspec

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
1-
# -*- encoding: utf-8 -*-
2-
$:.push File.expand_path("../lib", __FILE__)
3-
require "queue_bus/version"
1+
# frozen_string_literal: true
2+
3+
$:.push File.expand_path('lib', __dir__)
4+
require 'queue_bus/version'
45

56
Gem::Specification.new do |s|
6-
s.name = "queue-bus"
7+
s.name = 'queue-bus'
78
s.version = QueueBus::VERSION
8-
s.authors = ["Brian Leonard"]
9-
s.email = ["[email protected]"]
10-
s.homepage = ""
11-
s.summary = %q{A simple event bus on top of background queues}
12-
s.description = %q{A simple event bus on top of common background queues. Publish and subscribe to events as they occur using what you already have.}
9+
s.authors = ['Brian Leonard']
10+
s.email = ['[email protected]']
11+
s.homepage = ''
12+
s.summary = 'A simple event bus on top of background queues'
13+
s.description = 'A simple event bus on top of common background queues. Publish and subscribe to events as they occur using what you already have.'
1314

14-
s.rubyforge_project = "queue-bus"
15+
s.rubyforge_project = 'queue-bus'
1516

1617
s.files = `git ls-files`.split("\n")
1718
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19-
s.require_paths = ["lib"]
19+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
20+
s.require_paths = ['lib']
2021

21-
s.add_dependency("multi_json")
22-
s.add_dependency("redis")
22+
s.add_dependency('multi_json')
23+
s.add_dependency('redis')
2324

2425
# if using resque
2526
# s.add_development_dependency('resque', ['>= 1.10.0', '< 2.0'])
2627
# s.add_development_dependency('resque-scheduler', '>= 2.0.1')
2728
# s.add_development_dependency('resque-retry')
2829

29-
s.add_development_dependency("rspec")
30-
s.add_development_dependency("timecop")
31-
s.add_development_dependency("json_pure")
32-
s.add_development_dependency("rubocop")
30+
s.add_development_dependency('json_pure')
31+
s.add_development_dependency('rspec')
32+
s.add_development_dependency('rubocop')
33+
s.add_development_dependency('timecop')
3334
end

spec/adapter/publish_at_spec.rb

+28-25
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
1-
require 'spec_helper'
1+
# frozen_string_literal: true
22

3-
describe "Publishing an event in the future" do
3+
require 'spec_helper'
44

5+
describe 'Publishing an event in the future' do
56
before(:each) do
67
Timecop.freeze(now)
7-
allow(QueueBus).to receive(:generate_uuid).and_return("idfhlkj")
8+
allow(QueueBus).to receive(:generate_uuid).and_return('idfhlkj')
89
end
910
after(:each) do
1011
Timecop.return
1112
end
12-
let(:delayed_attrs) { {
13-
"bus_delayed_until" => future.to_i,
14-
"bus_id" => "#{now.to_i}-idfhlkj",
15-
"bus_app_hostname" => `hostname 2>&1`.strip.sub(/.local/,'')} }
13+
let(:delayed_attrs) do
14+
{
15+
'bus_delayed_until' => future.to_i,
16+
'bus_id' => "#{now.to_i}-idfhlkj",
17+
'bus_app_hostname' => `hostname 2>&1`.strip.sub(/.local/, '')
18+
}
19+
end
1620

17-
let(:bus_attrs) { delayed_attrs.merge({"bus_published_at" => worktime.to_i})}
18-
let(:now) { Time.parse("01/01/2013 5:00")}
21+
let(:bus_attrs) { delayed_attrs.merge('bus_published_at' => worktime.to_i) }
22+
let(:now) { Time.parse('01/01/2013 5:00') }
1923
let(:future) { Time.at(now.to_i + 60) }
20-
let(:worktime) {Time.at(future.to_i + 1)}
24+
let(:worktime) { Time.at(future.to_i + 1) }
2125

22-
it "should add it to Redis then to the real queue" do
23-
hash = {:one => 1, "two" => "here", "id" => 12 }
24-
event_name = "event_name"
26+
it 'should add it to Redis then to the real queue' do
27+
hash = { :one => 1, 'two' => 'here', 'id' => 12 }
28+
event_name = 'event_name'
2529
QueueBus.publish_at(future, event_name, hash)
2630

27-
schedule = QueueBus.redis { |redis| redis.zrange("delayed_queue_schedule", 0, 1) }
31+
schedule = QueueBus.redis { |redis| redis.zrange('delayed_queue_schedule', 0, 1) }
2832
expect(schedule).to eq([future.to_i.to_s])
2933

3034
val = QueueBus.redis { |redis| redis.lpop("delayed:#{future.to_i}") }
3135
hash = JSON.parse(val)
3236

33-
expect(hash["class"]).to eq("QueueBus::Worker")
34-
expect(hash["args"].size).to eq(1)
35-
expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy"=>"QueueBus::Publisher", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(delayed_attrs))
36-
expect(hash["queue"]).to eq("bus_incoming")
37+
expect(hash['class']).to eq('QueueBus::Worker')
38+
expect(hash['args'].size).to eq(1)
39+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'QueueBus::Publisher', 'bus_event_type' => 'event_name', 'two' => 'here', 'one' => 1, 'id' => 12 }.merge(delayed_attrs))
40+
expect(hash['queue']).to eq('bus_incoming')
3741

38-
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
42+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
3943
expect(val).to eq(nil) # nothing really added
4044

4145
Timecop.freeze(worktime)
42-
QueueBus::Publisher.perform(JSON.parse(hash["args"].first))
46+
QueueBus::Publisher.perform(JSON.parse(hash['args'].first))
4347

44-
val = QueueBus.redis { |redis| redis.lpop("queue:bus_incoming") }
48+
val = QueueBus.redis { |redis| redis.lpop('queue:bus_incoming') }
4549
hash = JSON.parse(val)
46-
expect(hash["class"]).to eq("QueueBus::Worker")
47-
expect(hash["args"].size).to eq(1)
48-
expect(JSON.parse(hash["args"].first)).to eq({"bus_class_proxy"=>"QueueBus::Driver", "bus_event_type"=>"event_name", "two"=>"here", "one"=>1, "id" => 12}.merge(bus_attrs))
50+
expect(hash['class']).to eq('QueueBus::Worker')
51+
expect(hash['args'].size).to eq(1)
52+
expect(JSON.parse(hash['args'].first)).to eq({ 'bus_class_proxy' => 'QueueBus::Driver', 'bus_event_type' => 'event_name', 'two' => 'here', 'one' => 1, 'id' => 12 }.merge(bus_attrs))
4953
end
50-
5154
end

spec/adapter/support.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'redis'
24

35
def reset_test_adapter

spec/adapter_spec.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

3-
describe "adapter is set" do
5+
describe 'adapter is set' do
46
it "should call it's enabled! method on init" do
57
QueueBus.send(:reset)
68
expect_any_instance_of(adapter_under_test_class).to receive(:enabled!)
79
instance = adapter_under_test_class.new
810
QueueBus.send(:reset)
911
end
1012

11-
it "should be defaulting to Data from spec_helper" do
13+
it 'should be defaulting to Data from spec_helper' do
1214
expect(QueueBus.adapter.is_a?(adapter_under_test_class)).to eq(true)
1315
end
1416
end

0 commit comments

Comments
 (0)