Skip to content

Commit 76a3bcd

Browse files
committed
fix standardrb complaints (then fix fixed code)
1 parent 5320d68 commit 76a3bcd

22 files changed

+134
-150
lines changed

lib/active_job/queue_adapters/litejob_adapter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def enqueue(job) # :nodoc:
3030
end
3131

3232
def enqueue_at(job, time) # :nodoc:
33-
time = time.from_now if time.respond_to?(:from_now) #is_a?(ActiveSupport::Duration)
33+
time = time.from_now if time.respond_to?(:from_now) # is_a?(ActiveSupport::Duration)
3434
Job.queue = job.queue_name
3535
Job.perform_at(time, job.serialize)
3636
end

lib/active_record/connection_adapters/litedb_adapter.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ module DatabaseTasks
9292
end
9393
end
9494

95-
ActiveRecord::ConnectionAdapters.register(
96-
"litedb", "ActiveRecord::ConnectionAdapters::LitedbAdapter",
97-
"active_record/connection_adapters/litedb_adapter"
98-
) if ActiveRecord::ConnectionAdapters.respond_to?(:register)
99-
100-
95+
if ActiveRecord::ConnectionAdapters.respond_to?(:register)
96+
ActiveRecord::ConnectionAdapters.register(
97+
"litedb", "ActiveRecord::ConnectionAdapters::LitedbAdapter",
98+
"active_record/connection_adapters/litedb_adapter"
99+
)
100+
end

lib/active_support/cache/litecache.rb

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
module ActiveSupport
88
module Cache
9-
109
self.format_version = 7.0
1110

1211
class Litecache < Store

lib/litestack/liteboard/liteboard.rb

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Liteboard
1212
@@res_mapping = {"hour" => "minute", "day" => "hour", "week" => "day", "year" => "week"}
1313
@@templates = {}
1414
@@app = proc do |env|
15-
case path = env["PATH_INFO"]
15+
case env["PATH_INFO"]
1616
when "/"
1717
Liteboard.new(env).call(:index)
1818
when "/topics/Litejob"
@@ -24,13 +24,12 @@ class Liteboard
2424
when "/topics/Litecable"
2525
Liteboard.new(env).call(:litecable)
2626
end
27-
2827
end
2928

3029
def initialize(env)
3130
@env = env
3231
@req = Rack::Request.new(@env)
33-
@params = @req.params
32+
@params = @req.params
3433
@running = true
3534
@lm = Litemetric.instance
3635
end
@@ -224,7 +223,7 @@ def litejob
224223
@events.each do |event|
225224
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event[:name])
226225
event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] }
227-
event["values"] = data_points.collect { |r| [r["rtime"], (r["rtotal"] || 0.0)] }
226+
event["values"] = data_points.collect { |r| [r["rtime"], r["rtotal"] || 0.0] }
228227
end
229228
@snapshot = read_snapshot(@topic)
230229
@size = begin

lib/litestack/litecache.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def set_unless_exists(key, value, expires_in = nil)
125125
# if the key doesn't exist or it is expired then null will be returned
126126
def get(key)
127127
key = key.to_s
128-
if (record = run_stmt(:getter, key)[0])
128+
if (record = run_stmt(:getter, key)[0])
129129
capture(:get, key, 1)
130130
return record[1]
131131
end
@@ -223,7 +223,7 @@ def snapshot
223223
}
224224
}
225225
end
226-
226+
227227
private
228228

229229
def setup

lib/litestack/liteconnection.rb

+8-12
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def configure(options = {})
7070
end
7171
@options = defaults.merge(options)
7272
config = begin
73-
YAML.load(ERB.new(File.read(@options[:config_path])).result)
73+
YAML.safe_load(ERB.new(File.read(@options[:config_path])).result)
7474
rescue
7575
{}
7676
end # an empty hash won't hurt
@@ -122,24 +122,20 @@ def acquire_connection
122122
if @checked_out_conn
123123
yield @checked_out_conn
124124
else
125-
@conn.acquire{ |conn| yield conn }
125+
@conn.acquire { |conn| yield conn }
126126
end
127127
end
128128

129-
# this will force the other run_* methods to use the
129+
# this will force the other run_* methods to use the
130130
# checked out connection if one exists
131131
def with_connection
132-
@conn.acquire do |conn|
133-
begin
134-
@checked_out_conn = conn
135-
yield conn
136-
ensure
137-
@checked_out_conn = nil
138-
end
132+
@conn.acquire do |conn|
133+
@checked_out_conn = conn
134+
yield conn
135+
ensure
136+
@checked_out_conn = nil
139137
end
140138
end
141-
142-
143139

144140
def create_pooled_connection(count = 1)
145141
count = 1 unless count&.is_a?(Integer)

lib/litestack/litejobqueue.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ def stop
137137
# @@queue = nil
138138
close
139139
end
140-
140+
141141
private
142-
142+
143143
def prepare_search_options(opts)
144144
sql_opts = super(opts)
145145
sql_opts[:klass] = opts[:klass]
146146
sql_opts[:params] = opts[:params]
147-
sql_opts
147+
sql_opts
148148
end
149149

150150
def exit_callback
@@ -189,15 +189,15 @@ def schedule(spawn = false, &block)
189189
# create a worker according to environment
190190
def create_worker
191191
# temporarily stop this feature until a better solution is implemented
192-
#return if defined?(Rails) && !defined?(Rails::Server)
192+
# return if defined?(Rails) && !defined?(Rails::Server)
193193
Litescheduler.spawn do
194194
worker_sleep_index = 0
195195
while @running
196196
processed = 0
197197
@queues.each do |priority, queues| # iterate through the levels
198198
queues.each do |queue, spawns| # iterate through the queues in the level
199199
batched = 0
200-
200+
201201
while (batched < priority) && (payload = pop(queue, 1)) # fearlessly use the same queue object
202202
capture(:dequeue, queue)
203203
processed += 1

lib/litestack/litequeue.rb

+22-6
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def snapshot
111111
queues: queues
112112
}
113113
end
114-
114+
115115
def find(opts = {})
116116
run_stmt(:search, prepare_search_options(opts))
117117
end
@@ -120,12 +120,28 @@ def find(opts = {})
120120

121121
def prepare_search_options(opts)
122122
sql_opts = {}
123-
sql_opts[:fire_at_from] = opts[:fire_at][0] rescue nil
124-
sql_opts[:fire_at_to] = opts[:fire_at][1] rescue nil
125-
sql_opts[:created_at_from] = opts[:created_at][0] rescue nil
126-
sql_opts[:created_at_to] = opts[:created_at][1] rescue nil
123+
sql_opts[:fire_at_from] = begin
124+
opts[:fire_at][0]
125+
rescue
126+
nil
127+
end
128+
sql_opts[:fire_at_to] = begin
129+
opts[:fire_at][1]
130+
rescue
131+
nil
132+
end
133+
sql_opts[:created_at_from] = begin
134+
opts[:created_at][0]
135+
rescue
136+
nil
137+
end
138+
sql_opts[:created_at_to] = begin
139+
opts[:created_at][1]
140+
rescue
141+
nil
142+
end
127143
sql_opts[:name] = opts[:queue]
128-
sql_opts[:dir] = opts[:dir] == :desc ? -1 : 1
144+
sql_opts[:dir] = (opts[:dir] == :desc) ? -1 : 1
129145
sql_opts
130146
end
131147

lib/litestack/litescheduler.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def synchronize(&block)
7878
end
7979
end
8080
end
81-
81+
8282
module ForkListener
8383
def self.listeners
8484
@listeners ||= []
@@ -99,7 +99,6 @@ def _fork(*args)
9999
result
100100
end
101101
end
102-
103102
end
104103

105104
Process.singleton_class.prepend(Litescheduler::Forkable)

lib/litestack/litesearch/model.rb

+15-14
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ def similar(limit = 10)
4242
end
4343

4444
module ClassMethods
45-
4645
def litesearch
4746
# it is possible that this code is running when there is no table created yet
4847
if !defined?(ActiveRecord::Base).nil? && ancestors.include?(ActiveRecord::Base)
4948
unless table_exists?
5049
# capture the schema block
5150
@schema = ::Litesearch::Schema.new
5251
@schema.model_class = self if @schema.respond_to? :model_class
53-
@schema.type :backed
52+
@schema.type :backed
5453
@schema.table table_name.to_sym
5554
yield @schema
5655
@schema.post_init
@@ -137,29 +136,31 @@ def create_instance(row)
137136
end
138137

139138
module ActiveRecordSchemaMethods
140-
141139
attr_accessor :model_class
142-
140+
143141
def field(name, attributes = {})
144142
keys = attributes.keys
145143
if keys.include?(:action_text) || keys.include?(:rich_text)
146-
attributes[:source] = "#{ActionText::RichText.table_name}.body" rescue "action_text_rich_texts.body"
147-
attributes[:reference] = :record_id
148-
attributes[:conditions] = { record_type: model_class.name }
144+
attributes[:source] = begin
145+
"#{ActionText::RichText.table_name}.body"
146+
rescue
147+
"action_text_rich_texts.body"
148+
end
149+
attributes[:reference] = :record_id
150+
attributes[:conditions] = {record_type: model_class.name}
149151
attributes[:target] = nil
150152
elsif keys.include? :as
151-
attributes[:source] = attributes[:target] unless attributes[:source]
153+
attributes[:source] = attributes[:target] unless attributes[:source]
152154
attributes[:reference] = "#{attributes[:as]}_id"
153-
attributes[:conditions] = {"#{attributes[:as]}_type".to_sym => model_class.name }
155+
attributes[:conditions] = {"#{attributes[:as]}_type": model_class.name}
154156
attributes[:target] = nil
155157
end
156158
super(name, attributes)
157-
end
159+
end
158160

159-
def allowed_attributes
160-
super + [:polymorphic, :as, :action_text]
161-
end
162-
161+
def allowed_attributes
162+
super + [:polymorphic, :as, :action_text]
163+
end
163164
end
164165

165166
module ActiveRecordInstanceMethods; end

lib/litestack/litesearch/schema.rb

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
require_relative "schema_adapters"
22

33
class Litesearch::Schema
4-
54
TOKENIZERS = {
65
porter: "porter unicode61 remove_diacritics 2",
76
unicode: "unicode61 remove_diacritics 2",

lib/litestack/litesearch/schema_adapters/backed_adapter.rb

+14-18
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ def drop_primary_triggers_sql
2525

2626
def create_primary_triggers_sql(active = false)
2727
when_stmt = "TRUE"
28-
cols = active_cols_names.select{|n| !n.nil?}
28+
cols = active_cols_names.select { |n| !n.nil? }
2929
if (filter = @schema[:filter_column])
3030
when_stmt = "NEW.#{filter} = TRUE"
3131
cols << filter
3232
end
33-
update_filter = String.new
33+
update_filter = +""
3434
if cols.length > 0
35-
" OF #{cols.join(', ')} "
35+
" OF #{cols.join(", ")} "
3636
end
3737

3838
<<-SQL
@@ -68,7 +68,7 @@ def create_secondary_trigger_sql(target_table, target_col, col)
6868
end
6969

7070
def create_secondary_trigger_poly_sql(target_table, target_col, col, conditions)
71-
conditions_sql = conditions.collect{|k, v| "NEW.#{k} = '#{v}'"}.join(" AND ")
71+
conditions_sql = conditions.collect { |k, v| "NEW.#{k} = '#{v}'" }.join(" AND ")
7272
<<~SQL
7373
CREATE TRIGGER IF NOT EXISTS #{target_table}_#{target_col}_#{name}_insert AFTER INSERT ON #{target_table} WHEN #{conditions_sql} BEGIN
7474
#{rebuild_sql};
@@ -79,10 +79,8 @@ def create_secondary_trigger_poly_sql(target_table, target_col, col, conditions)
7979
SQL
8080
end
8181

82-
83-
8482
def drop_secondary_triggers_sql
85-
sql = String.new
83+
sql = +""
8684
@schema[:fields].each do |name, field|
8785
if field[:trigger_sql]
8886
if field[:col]
@@ -96,7 +94,7 @@ def drop_secondary_triggers_sql
9694
end
9795

9896
def create_secondary_triggers_sql
99-
sql = String.new
97+
sql = +""
10098
@schema[:fields].each do |name, field|
10199
if field[:trigger_sql]
102100
if field[:col]
@@ -129,11 +127,11 @@ def enrich_schema
129127
target_table, target_col = field[:source].split(".")
130128
field[:target_table] = target_table.to_sym
131129
field[:target_col] = target_col.to_sym
132-
field[:conditions_sql] = field[:conditions].collect{|k, v| "#{k} = '#{v}'"}.join(" AND ") if field[:conditions]
130+
field[:conditions_sql] = field[:conditions].collect { |k, v| "#{k} = '#{v}'" }.join(" AND ") if field[:conditions]
133131
field[:sql] = "SELECT #{field[:target_col]} FROM #{field[:target_table]} WHERE #{field[:reference]} = NEW.id"
134-
field[:sql] += " AND #{field[:conditions_sql]}" if field[:conditions_sql]
132+
field[:sql] += " AND #{field[:conditions_sql]}" if field[:conditions_sql]
135133
field[:sql] = "(#{field[:sql]})"
136-
field[:trigger_sql] = true
134+
field[:trigger_sql] = true
137135
field[:target_table_alias] = "#{field[:target_table]}_#{name}"
138136
else
139137
field[:col] = name unless field[:col]
@@ -145,7 +143,7 @@ def enrich_schema
145143
end
146144

147145
def filter_sql
148-
sql = String.new
146+
sql = +""
149147
sql << " WHERE #{@schema[:filter_column]} = TRUE " if @schema[:filter_column]
150148
sql
151149
end
@@ -161,27 +159,25 @@ def select_cols_sql
161159
(!field[:trigger_sql].nil?) ? "#{field[:target_table_alias]}.#{field[:target_col]}" : field[:target]
162160
end.join(", ")
163161
end
164-
162+
165163
def joins_sql
166164
joins = [@schema[:table]]
167165
active_fields.each do |name, field|
168166
if field[:trigger_sql]
169-
join_table = String.new
167+
join_table = +""
170168
join_table << "#{field[:target_table]} AS #{field[:target_table_alias]} ON "
171169
if field[:col]
172170
join_table << "#{field[:target_table_alias]}.id = #{@schema[:table]}.#{field[:col]}" if field[:col]
173171
elsif field[:source]
174172
join_table << "#{field[:target_table_alias]}.#{field[:reference]} = #{@schema[:table]}.id"
175173
if field[:conditions]
176174
join_table << " AND "
177-
join_table << field[:conditions].collect{|k, v| "#{field[:target_table_alias]}.#{k} = '#{v}'"}.join(" AND ")
175+
join_table << field[:conditions].collect { |k, v| "#{field[:target_table_alias]}.#{k} = '#{v}'" }.join(" AND ")
178176
end
179177
end
180-
joins << join_table
178+
joins << join_table
181179
end
182180
end
183181
joins.join(" LEFT JOIN ")
184182
end
185-
186-
187183
end

0 commit comments

Comments
 (0)