From db0d99bbf4c8431c3319479dab6f6538d8ff989d Mon Sep 17 00:00:00 2001 From: Guillaume Grossetie Date: Fri, 21 May 2021 08:37:38 +0200 Subject: [PATCH] resolves #257 pass logger as config (#260) --- .github/workflows/build-ruby.yml | 10 ++++++---- ruby/Gemfile.lock | 2 +- .../extensions/asciidoctor_kroki/extension.rb | 12 ++++++------ ruby/spec/asciidoctor_kroki_spec.rb | 11 +++++++++++ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build-ruby.yml b/.github/workflows/build-ruby.yml index 7f36775b..996799eb 100644 --- a/.github/workflows/build-ruby.yml +++ b/.github/workflows/build-ruby.yml @@ -13,10 +13,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-ruby@v1 + - uses: ruby/setup-ruby@v1 with: - ruby-version: '2.6' - - run: bundle install - working-directory: ./ruby + ruby-version: 2.7 + bundler-cache: true + working-directory: ./ruby - run: bundle exec rake working-directory: ./ruby + env: + RUBYOPT: "W:deprecated" diff --git a/ruby/Gemfile.lock b/ruby/Gemfile.lock index de6cbb19..274ade4f 100644 --- a/ruby/Gemfile.lock +++ b/ruby/Gemfile.lock @@ -49,4 +49,4 @@ DEPENDENCIES rubocop (~> 0.74.0) BUNDLED WITH - 1.17.3 + 2.2.17 diff --git a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb index 9652826d..2f734b07 100644 --- a/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb +++ b/ruby/lib/asciidoctor/extensions/asciidoctor_kroki/extension.rb @@ -17,11 +17,11 @@ class KrokiBlockProcessor < Extensions::BlockProcessor # @param name [String] name of the block macro (optional) # @param config [Hash] a config hash (optional) - # @param logger [Logger] a logger used to log warning and errors (optional) + # - :logger a logger used to log warning and errors (optional) # - def initialize(name = nil, config = {}, logger: ::Asciidoctor::LoggerManager.logger) + def initialize(name = nil, config = {}) + @logger = (config || {}).delete(:logger) { ::Asciidoctor::LoggerManager.logger } super(name, config) - @logger = logger end def process(parent, reader, attrs) @@ -44,11 +44,11 @@ class KrokiBlockMacroProcessor < Asciidoctor::Extensions::BlockMacroProcessor # @param name [String] name of the block macro (optional) # @param config [Hash] a config hash (optional) - # @param logger [Logger] a logger used to log warning and errors (optional) + # - :logger a logger used to log warning and errors (optional) # - def initialize(name = nil, config = {}, logger: ::Asciidoctor::LoggerManager.logger) + def initialize(name = nil, config = {}) + @logger = (config || {}).delete(:logger) { ::Asciidoctor::LoggerManager.logger } super(name, config) - @logger = logger end def process(parent, target, attrs) diff --git a/ruby/spec/asciidoctor_kroki_spec.rb b/ruby/spec/asciidoctor_kroki_spec.rb index 8d02774c..c8976bf1 100644 --- a/ruby/spec/asciidoctor_kroki_spec.rb +++ b/ruby/spec/asciidoctor_kroki_spec.rb @@ -130,6 +130,17 @@ ) end end + context 'instantiate' do + it 'should instantiate block processor without warning' do + original_stderr = $stderr + $stderr = StringIO.new + ::AsciidoctorExtensions::KrokiBlockProcessor.new 'plantuml'.to_sym, {} + output = $stderr.string + (expect output).to eql '' + ensure + $stderr = original_stderr + end + end end describe ::AsciidoctorExtensions::Kroki do