Skip to content

Commit

Permalink
Modernize gem. Prefer sus-fixtures-console for captured logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 5, 2024
1 parent 076f777 commit 3f95f0a
Show file tree
Hide file tree
Showing 54 changed files with 262 additions and 286 deletions.
20 changes: 4 additions & 16 deletions .github/workflows/rubocop.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test External
name: RuboCop

on: [push, pull_request]

Expand All @@ -9,26 +9,14 @@ env:
CONSOLE_OUTPUT: XTerm

jobs:
test:
name: ${{matrix.ruby}} on ${{matrix.os}}
runs-on: ${{matrix.os}}-latest

strategy:
matrix:
os:
- ubuntu
- macos

ruby:
- "3.1"
- "3.2"
- "3.3"
check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{matrix.ruby}}
ruby-version: ruby
bundler-cache: true

- name: Run RuboCop
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ jobs:
- name: Run tests
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
7 changes: 7 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Layout/IndentationConsistency:
Enabled: true
EnforcedStyle: normal

Layout/BlockAlignment:
Enabled: true

Layout/EndAlignment:
Enabled: true
EnforcedStyleAlignWith: start_of_line
Expand Down Expand Up @@ -44,3 +47,7 @@ Layout/EmptyLinesAroundModuleBody:

Style/FrozenStringLiteralComment:
Enabled: true

Style/StringLiterals:
Enabled: true
EnforcedStyle: double_quotes
2 changes: 1 addition & 1 deletion bake.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, 2020-2022, by Samuel Williams.
# Copyright, 2020-2024, by Samuel Williams.

# Update the project documentation with the new version number.
#
Expand Down
6 changes: 3 additions & 3 deletions bake/console.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

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

# Increase the verbosity of the logger to info.
def info
require_relative '../lib/console'
require_relative "../lib/console"

Console.logger.info!
end

# Increase the verbosity of the logger to debug.
def debug
require_relative '../lib/console'
require_relative "../lib/console"

Console.logger.debug!
end
6 changes: 3 additions & 3 deletions benchmark/fiber_vs_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# frozen_string_literal: true

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

require 'benchmark/ips'
require 'fiber'
require "benchmark/ips"
require "fiber"

# GC.disable

Expand Down
4 changes: 2 additions & 2 deletions config/sus.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, by Samuel Williams.
# Copyright, 2022-2024, by Samuel Williams.

require 'covered/sus'
require "covered/sus"
include Covered::Sus
6 changes: 3 additions & 3 deletions console.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ Gem::Specification.new do |spec|
spec.authors = ["Samuel Williams", "Robert Schulze", "Bryan Powell", "Michael Adams", "Anton Sozontov", "Cyril Roelandt", "Cédric Boutillier", "Felix Yan", "Olle Jonsson", "Patrik Wenger", "William T. Nelson"]
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://socketry.github.io/console"

spec.metadata = {
"documentation_uri" => "https://socketry.github.io/console/",
}

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"

Expand Down
12 changes: 6 additions & 6 deletions examples/datadog/gems.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, 2022-2023, by Samuel Williams.
# Copyright, 2022-2024, by Samuel Williams.

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

gem 'traces'
gem 'traces-backend-datadog'
gem "traces"
gem "traces-backend-datadog"

gem 'console', path: '../..'
gem 'console-output-datadog'
gem "console", path: "../.."
gem "console-output-datadog"
18 changes: 9 additions & 9 deletions examples/datadog/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# frozen_string_literal: true

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

# Run this using `systemd-cat bundle exec ./integration.rb`
# This will send logs to datadog using the standard systemd journal.

ENV['TRACES_BACKEND'] ||= 'traces/backend/datadog'
ENV['CONSOLE_OUTPUT'] ||= 'Console::Output::Datadog,Console::Output::Default'
ENV["TRACES_BACKEND"] ||= "traces/backend/datadog"
ENV["CONSOLE_OUTPUT"] ||= "Console::Output::Datadog,Console::Output::Default"

require 'ddtrace'
require "ddtrace"

require 'traces'
require 'console/output/datadog'
require 'console'
require "traces"
require "console/output/datadog"
require "console"

# Standard log levels according to syslog:
# Fatal: system is unusable
Expand All @@ -41,9 +41,9 @@ def call(message)

Traces::Provider(self) do
def call(message)
trace('logly.call') {super}
trace("logly.call") {super}
end
end
end

Logly.new.call('Hello, world!')
Logly.new.call("Hello, world!")
23 changes: 0 additions & 23 deletions fixtures/console/captured_output.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# Copyright, 2020, by Michael Adams.
# Copyright, 2021, by Cédric Boutillier.

require_relative 'console/version'
require_relative 'console/logger'
require_relative 'console/warn'
require_relative "console/version"
require_relative "console/logger"
require_relative "console/warn"

module Console
class << self
Expand Down
2 changes: 1 addition & 1 deletion lib/console/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require_relative 'filter'
require_relative "filter"

module Console
# A general sink which captures all events into a buffer.
Expand Down
2 changes: 1 addition & 1 deletion lib/console/compatible/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2022-2024, by Samuel Williams.

require 'logger'
require "logger"

module Console
module Compatible
Expand Down
4 changes: 2 additions & 2 deletions lib/console/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require_relative 'event/spawn'
require_relative 'event/failure'
require_relative "event/spawn"
require_relative "event/failure"
4 changes: 2 additions & 2 deletions lib/console/event/failure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Copyright, 2021, by Robert Schulze.
# Copyright, 2024, by Patrik Wenger.

require_relative 'generic'
require_relative "generic"

module Console
module Event
Expand Down Expand Up @@ -59,7 +59,7 @@ def extract(exception, hash)
message = exception.detailed_message

# We want to remove the trailling exception class as we format it differently:
message.sub!(/\s*\(.*?\)$/, '')
message.sub!(/\s*\(.*?\)$/, "")

hash[:message] = message
else
Expand Down
4 changes: 2 additions & 2 deletions lib/console/event/spawn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.

require_relative 'generic'
require_relative '../clock'
require_relative "generic"
require_relative "../clock"

module Console
module Event
Expand Down
2 changes: 1 addition & 1 deletion lib/console/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Console
UNKNOWN = :unknown

class Filter
if Object.const_defined?(:Ractor) and RUBY_VERSION >= '3.1'
if Object.const_defined?(:Ractor) and RUBY_VERSION >= "3.1"
def self.define_immutable_method(name, &block)
block = Ractor.make_shareable(block)
self.define_method(name, &block)
Expand Down
2 changes: 1 addition & 1 deletion lib/console/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.

require_relative 'format/safe'
require_relative "format/safe"

module Console
module Format
Expand Down
4 changes: 2 additions & 2 deletions lib/console/format/safe.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, 2023, by Samuel Williams.
# Copyright, 2023-2024, by Samuel Williams.

require 'json'
require "json"

module Console
module Format
Expand Down
16 changes: 8 additions & 8 deletions lib/console/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
# Copyright, 2021, by Bryan Powell.
# Copyright, 2021, by Robert Schulze.

require_relative 'output'
require_relative 'filter'
require_relative 'event'
require_relative 'resolver'
require_relative 'progress'
require_relative "output"
require_relative "filter"
require_relative "event"
require_relative "resolver"
require_relative "progress"

require 'fiber/local'
require "fiber/local"

module Console
class Logger < Filter[debug: 0, info: 1, warn: 2, error: 3, fatal: 4]
Expand All @@ -21,7 +21,7 @@ class Logger < Filter[debug: 0, info: 1, warn: 2, error: 3, fatal: 4]
# You can also specify CONSOLE_LEVEL=debug or CONSOLE_LEVEL=info in environment.
# https://mislav.net/2011/06/ruby-verbose-mode/ has more details about how it all fits together.
def self.default_log_level(env = ENV)
if level = env['CONSOLE_LEVEL']
if level = env["CONSOLE_LEVEL"]
LEVELS[level.to_sym] || level.to_i
elsif $DEBUG
DEBUG
Expand All @@ -34,7 +34,7 @@ def self.default_log_level(env = ENV)

# Controls verbose output using `$VERBOSE`.
def self.verbose?(env = ENV)
!$VERBOSE.nil? || env['CONSOLE_VERBOSE']
!$VERBOSE.nil? || env["CONSOLE_VERBOSE"]
end

def self.default_logger(output = $stderr, env = ENV, **options)
Expand Down
12 changes: 6 additions & 6 deletions lib/console/output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
# Released under the MIT License.
# Copyright, 2021-2024, by Samuel Williams.

require_relative 'output/default'
require_relative 'output/serialized'
require_relative 'output/terminal'
require_relative 'output/null'
require_relative "output/default"
require_relative "output/serialized"
require_relative "output/terminal"
require_relative "output/null"

module Console
module Output
def self.new(output = nil, env = ENV, **options)
if names = env['CONSOLE_OUTPUT']
names = names.split(',').reverse
if names = env["CONSOLE_OUTPUT"]
names = names.split(",").reverse

names.inject(output) do |output, name|
Output.const_get(name).new(output, **options)
Expand Down
Loading

0 comments on commit 3f95f0a

Please sign in to comment.