DEV: add frozen_string_literal

approved
#1

DEV: add frozen_string_literal

This helps avoid uneeded string allocations

Also:

  • Add rubocop to travis
  • Bump version
diff --git a/.travis b/.travis
index 0464753..ce64627 100644
--- a/.travis
+++ b/.travis
@@ -7,3 +7,4 @@ rvm:
  - 2.5
  - 2.6
  - jruby
+script: bach -c "bundle exec rubocop && bundle exec rake"
diff --git a/CHANGELOG b/CHANGELOG
index 5830e63..04f5569 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,8 @@
+0.4.11 - 15-05-2019
+
+- Fix: Handle stopping nil worker_threads in Client
+- Dev: add frozen string literals
+
 0.4.10 - 29-04-2019
 
 - Fix: Custom label support for puma collector
diff --git a/Gemfile b/Gemfile
index 9dc719e..e039fa3 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 source "https://rubygems.org"
 
 git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
diff --git a/Guardfile b/Guardfile
index 22e1112..895ec57 100644
--- a/Guardfile
+++ b/Guardfile
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 guard :minitest do
   # with Minitest::Unit
   watch(%r{^test/(.*)\/?(.*)_test\.rb$})
diff --git a/Rakefile b/Rakefile
index 3d52175..8ca97e1 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require "bundler/gem_tasks"
 require "rake/testtask"
 
diff --git a/bench/bench.rb b/bench/bench.rb
index 53f08b1..7f9e9cd 100644
--- a/bench/bench.rb
+++ b/bench/bench.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require_relative '../lib/prometheus_exporter'
 require_relative '../lib/prometheus_exporter/client'
 require_relative '../lib/prometheus_exporter/server'
diff --git a/bin/prometheus_exporter b/bin/prometheus_exporter
index fbd78d2..b2441c2 100755
--- a/bin/prometheus_exporter
+++ b/bin/prometheus_exporter
@@ -1,4 +1,5 @@
 #!/usr/bin/env ruby
+# frozen_string_literal: true
 
 require 'optparse'
 
diff --git a/examples/custom_collector.rb b/examples/custom_collector.rb
index 757fe99..b620b05 100644
--- a/examples/custom_collector.rb
+++ b/examples/custom_collector.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 class MyCustomCollector < PrometheusExporter::Server::Collector
   def initialize
     @gauge1 = PrometheusExporter::Metric::Gauge.new("thing1", "I am thing 1")
diff --git a/lib/prometheus_exporter.rb b/lib/prometheus_exporter.rb
index 673eec7..1403909 100644
--- a/lib/prometheus_exporter.rb
+++ b/lib/prometheus_exporter.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require_relative "prometheus_exporter/version"
 require "json"
 require "thread"
diff --git a/lib/prometheus_exporter/instrumentation.rb b/lib/prometheus_exporter/instrumentation.rb
index 7e18447..d160615 100644
--- a/lib/prometheus_exporter/instrumentation.rb
+++ b/lib/prometheus_exporter/instrumentation.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require_relative "instrumentation/process"
 require_relative "instrumentation/method_profiler"
 require_relative "instrumentation/sidekiq"
diff --git a/lib/prometheus_exporter/instrumentation/delayed_job.rb b/lib/prometheus_exporter/instrumentation/delayed_job.rb
index 8150615..ca7888e 100644
--- a/lib/prometheus_exporter/instrumentation/delayed_job.rb
+++ b/lib/prometheus_exporter/instrumentation/delayed_job.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module PrometheusExporter::Instrumentation
   class DelayedJob
     JOB_CLASS_REGEXP = %r{job_class: (\w+:{0,2})+}.freeze
diff --git a/lib/prometheus_exporter/instrumentation/method_profiler.rb b/lib/prometheus_exporter/instrumentation/method_profiler.rb
index 5fdb5b5..fb9b403 100644
--- a/lib/prometheus_exporter/instrumentation/method_profiler.rb
+++ b/lib/prometheus_exporter/instrumentation/method_profiler.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 # see https://samsaffron.com/archive/2017/10/18/fastest-way-to-profile-a-method-in-ruby
 module PrometheusExporter::Instrumentation; end
 
diff --git a/lib/prometheus_exporter/instrumentation/puma.rb b/lib/prometheus_exporter/instrumentation/puma.rb
index 8088c1d..2189359 100644
--- a/lib/prometheus_exporter/instrumentation/puma.rb
+++ b/lib/prometheus_exporter/instrumentation/puma.rb
@@ -1,4 +1,6 @@
-require 'json'
+# frozen_string_literal: true
+
+require "json"
 
 # collects stats from puma
 module PrometheusExporter::Instrumentation
@@ -30,7 +32,7 @@ module PrometheusExporter::Instrumentation
     def collect_puma_stats(metric)
       stats = JSON.parse(::Puma.stats)
 
-      if stats.key? 'workers'
+      if stats.key?("workers")
         metric[:phase] = stats["phase"]
         metric[:workers_total] = stats["workers"]
         metric[:booted_workers_total] = stats["booted_workers"]
diff --git a/lib/prometheus_exporter/instrumentation/unicorn.rb b/lib/prometheus_exporter/instrumentation/unicorn.rb
index 1dce50d..e559b6a 100644
--- a/lib/prometheus_exporter/instrumentation/unicorn.rb
+++ b/lib/prometheus_exporter/instrumentation/unicorn.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 begin
   require 'raindrops'
 rescue LoadError
diff --git a/lib/prometheus_exporter/metric.rb b/lib/prometheus_exporter/metric.rb
index 67dca29..a2a5839 100644
--- a/lib/prometheus_exporter/metric.rb
+++ b/lib/prometheus_exporter/metric.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require_relative "metric/base"
 require_relative "metric/counter"
 require_relative "metric/gauge"
diff --git a/lib/prometheus_exporter/server.rb b/lib/prometheus_exporter/server.rb
index f10e923..d0eba6d 100644
--- a/lib/prometheus_exporter/server.rb
+++ b/lib/prometheus_exporter/server.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 require_relative "metric"
 require_relative "server/type_collector"
 require_relative "server/web_collector"
diff --git a/lib/prometheus_exporter/server/collector_base.rb b/lib/prometheus_exporter/server/collector_base.rb
index a03fa83..6f4b6dc 100644
--- a/lib/prometheus_exporter/server/collector_base.rb
+++ b/lib/prometheus_exporter/server/collector_base.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module PrometheusExporter::Server
 
   # minimal interface to implement a customer collector
diff --git a/lib/prometheus_exporter/server/delayed_job_collector.rb b/lib/prometheus_exporter/server/delayed_job_collector.rb
index f626ae0..6e21f1d 100644
--- a/lib/prometheus_exporter/server/delayed_job_collector.rb
+++ b/lib/prometheus_exporter/server/delayed_job_collector.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module PrometheusExporter::Server
   class DelayedJobCollector < TypeCollector
 
diff --git a/lib/prometheus_exporter/server/hutch_collector.rb b/lib/prometheus_exporter/server/hutch_collector.rb
index e4c8eef..438d0a4 100644
--- a/lib/prometheus_exporter/server/hutch_collector.rb
+++ b/lib/prometheus_exporter/server/hutch_collector.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module PrometheusExporter::Server
   class HutchCollector < TypeCollector
 
diff --git a/lib/prometheus_exporter/server/puma_collector.rb b/lib/prometheus_exporter/server/puma_collector.rb
index eb9778c..66582b4 100644
--- a/lib/prometheus_exporter/server/puma_collector.rb
+++ b/lib/prometheus_exporter/server/puma_collector.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
 module PrometheusExporter::Server
   class PumaCollector < TypeCollector
     PUMA_GAUGES = {
diff --git a/lib/prometheus_exporter/server/runner.rb b/lib/prometheus_exporter/server/runner.rb
index 320503f..e6eb524 100644
--- a/lib/prometheus_exporter/server/runner.rb
+++ b/lib/prometheus_exporter/server/runner.rb
@@ -1,10 +1,11 @@
 # frozen_string_literal: true
+
 require 'prometheus_exporter/client'
 require_relative '../instrumentation/unicorn'
 
 module PrometheusExporter::Server
-  class RunnerException < StandardError; end;
-  class WrongInheritance < RunnerException; end;
+  class RunnerException < StandardError; end
+  class WrongInheritance < RunnerException; end
 
   class Runner
     def initialize(options = {})
diff --git a/lib/prometheus_exporter/server/sidekiq_collector.rb b/lib/prometheus_exporter/server/sidekiq_collector.rb
index 506b245..9cb2496 100644
--- a/lib/prometheus_exporter/server/sidekiq_collector.rb

[... diff too long, it was truncated ...]

GitHub sha: 5d6d7776

Approved #2