Skip to content

Commit

Permalink
Modernize gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Oct 12, 2024
1 parent 3db3a64 commit 9830b1e
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 52 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ jobs:
timeout-minutes: 5
run: bundle exec bake test

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
include-hidden-files: true
if-no-files-found: error
name: coverage-${{matrix.os}}-${{matrix.ruby}}
path: .covered.db

Expand All @@ -50,7 +52,7 @@ jobs:
ruby-version: "3.3"
bundler-cache: true

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4

- name: Validate coverage
timeout-minutes: 5
Expand Down
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ Layout/EmptyLinesAroundModuleBody:

Style/FrozenStringLiteralComment:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
6 changes: 3 additions & 3 deletions bake/metrics/capture.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.
# Copyright, 2023-2024, by Samuel Williams.

# Enable capturing metrics.
def capture
ENV['METRICS_BACKEND'] = 'metrics/backend/capture'
require 'metrics'
ENV["METRICS_BACKEND"] = "metrics/backend/capture"
require "metrics"
end

# Generate a list of metrics that have been captured.
Expand Down
2 changes: 1 addition & 1 deletion config/external.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metrics-backend-datadog:
url: https://github.com/socketry/metrics-backend-datadog.git
command: bundle exec rspec
command: bundle exec sus
6 changes: 3 additions & 3 deletions config/sus.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2022, by Samuel Williams.
# Copyright, 2022-2024, by Samuel Williams.

ENV['METRICS_BACKEND'] ||= 'metrics/backend/console'
ENV["METRICS_BACKEND"] ||= "metrics/backend/console"

require 'covered/sus'
require "covered/sus"
include Covered::Sus
4 changes: 2 additions & 2 deletions examples/testing/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require 'metrics/provider'
require "metrics/provider"

class MyApplication
def work
# ...
end

Metrics::Provider(self) do
WORK_METRIC = Metrics.metric('my_application.work.count', :counter, description: 'Work counter')
WORK_METRIC = Metrics.metric("my_application.work.count", :counter, description: "Work counter")

def work
WORK_METRIC.emit(1)
Expand Down
6 changes: 3 additions & 3 deletions examples/testing/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

ENV['METRICS_BACKEND'] ||= 'metrics/backend/test'
ENV["METRICS_BACKEND"] ||= "metrics/backend/test"

require_relative 'app'
require_relative "app"

describe MyApplication do
it 'should emit metrics' do
it "should emit metrics" do
expect(MyApplication::WORK_METRIC).to receive(:emit).with(1)
MyApplication.new.work
end
Expand Down
2 changes: 1 addition & 1 deletion gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

Expand Down
8 changes: 4 additions & 4 deletions lib/metrics.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2022, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require_relative 'metrics/version'
require_relative 'metrics/provider'
require_relative 'metrics/tags'
require_relative "metrics/version"
require_relative "metrics/provider"
require_relative "metrics/tags"
6 changes: 3 additions & 3 deletions lib/metrics/backend.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'console/event/failure'
require "console/event/failure"

module Metrics
module Backend
# Require a specific trace backend.
def self.require_backend(env = ENV)
if backend = env['METRICS_BACKEND']
if backend = env["METRICS_BACKEND"]
begin
require(backend)
rescue LoadError => error
Expand Down
6 changes: 3 additions & 3 deletions lib/metrics/backend/capture.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.
# Copyright, 2023-2024, by Samuel Williams.

require 'console'
require_relative '../metric'
require "console"
require_relative "../metric"

module Metrics
module Backend
Expand Down
6 changes: 3 additions & 3 deletions lib/metrics/backend/console.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'console'
require_relative '../metric'
require "console"
require_relative "../metric"

module Metrics
module Backend
Expand Down
6 changes: 3 additions & 3 deletions lib/metrics/backend/test.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2022, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'console'
require_relative '../metric'
require "console"
require_relative "../metric"

module Metrics
module Backend
Expand Down
4 changes: 2 additions & 2 deletions lib/metrics/provider.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require_relative 'backend'
require_relative "backend"

module Metrics
# @returns [Boolean] Whether there is an active backend.
Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/tags.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2022, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

module Metrics
module Tags
Expand Down
2 changes: 1 addition & 1 deletion lib/metrics/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

module Metrics
VERSION = "0.10.2"
Expand Down
6 changes: 3 additions & 3 deletions metrics.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
spec.authors = ["Samuel Williams"]
spec.license = "MIT"

spec.cert_chain = ['release.cert']
spec.signing_key = File.expand_path('~/.gem/release.pem')
spec.cert_chain = ["release.cert"]
spec.signing_key = File.expand_path("~/.gem/release.pem")

spec.homepage = "https://github.com/socketry/metrics"

Expand All @@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
"source_code_uri" => "https://github.com/socketry/metrics.git",
}

spec.files = Dir.glob(['{bake,lib}/**/*', '*.md'], File::FNM_DOTMATCH, base: __dir__)
spec.files = Dir.glob(["{bake,lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)

spec.required_ruby_version = ">= 3.1"
end
6 changes: 3 additions & 3 deletions test/metrics.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2021-2023, by Samuel Williams.
# Copyright, 2021-2024, by Samuel Williams.

require 'metrics'
require "metrics"

class MyClass
def my_method(argument)
Expand All @@ -15,7 +15,7 @@ def my_method(argument)
end

Metrics::Provider(MyClass) do
MYCLASS_CALL_COUNT = Metrics.metric('my_class.call', :counter, description: 'Call counter.')
MYCLASS_CALL_COUNT = Metrics.metric("my_class.call", :counter, description: "Call counter.")

def my_method(argument)
MYCLASS_CALL_COUNT.emit(1, tags: ["foo", "bar"])
Expand Down
2 changes: 1 addition & 1 deletion test/metrics/backend.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2022-2023, by Samuel Williams.
# Copyright, 2024, by Samuel Williams.

require "metrics/backend"
require "json"
Expand Down
8 changes: 4 additions & 4 deletions test/metrics/backend/capture.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.
# Copyright, 2023-2024, by Samuel Williams.

require 'metrics/provider'
require "metrics/provider"

describe Metrics::Provider do
let(:document_root) {File.expand_path(".capture", __dir__)}
let(:environment) {{'METRICS_BACKEND' => nil}}
let(:environment) {{"METRICS_BACKEND" => nil}}

it "runs without metrics" do
pid = Process.spawn(environment, "bundle", "exec", "bake", "run", chdir: document_root)
Expand Down Expand Up @@ -57,7 +57,7 @@
"description" => be == "My metric",
"unit" => be == "seconds",
"values" => be == [1],
"tags" => be == ['environment:test'],
"tags" => be == ["environment:test"],
"sample_rates" => be == [1.0]
)
end
Expand Down
6 changes: 3 additions & 3 deletions test/metrics/metric.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.
# Copyright, 2023-2024, by Samuel Williams.

require 'metrics/metric'
require "metrics/metric"

describe Metrics::Metric do
let(:metric) {subject.new("my_metric", "gauge", "My metric", "seconds")}

it "can emit a metric" do
expect do
metric.emit(1, tags: ['environment:test'])
metric.emit(1, tags: ["environment:test"])
end.to raise_exception(NotImplementedError)
end
end
6 changes: 3 additions & 3 deletions test/metrics/provider.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2022, by Samuel Williams.
# Copyright, 2022-2024, by Samuel Williams.

unless ENV['METRICS_BACKEND']
unless ENV["METRICS_BACKEND"]
abort "No backend specified, tests will fail!"
end

require 'metrics/provider'
require "metrics/provider"

describe Metrics::Provider do
let(:my_class) {Class.new}
Expand Down

0 comments on commit 9830b1e

Please sign in to comment.