Skip to content

Commit

Permalink
add config & logger
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Sep 21, 2023
1 parent 0c7dc2d commit 14748d5
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 115 deletions.
2 changes: 2 additions & 0 deletions lib/relaton_ietf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
require "relaton/index"
require "relaton_bib"
require "relaton_ietf/version"
require "relaton_ietf/config"
require "relaton_ietf/util"
require "relaton_ietf/bibxml_parser"
require "relaton_ietf/ietf_bibliography"
require "relaton_ietf/xml_parser"
Expand Down
10 changes: 10 additions & 0 deletions lib/relaton_ietf/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module RelatonIetf
module Config
include RelatonBib::Config
end
extend Config

class Configuration < RelatonBib::Configuration
PROGNAME = "relaton-ietf".freeze
end
end
2 changes: 1 addition & 1 deletion lib/relaton_ietf/ietf_bibliographic_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IetfBibliographicItem < RelatonBib::BibliographicItem
# @param stream [String, nil]
def initialize(**args)
if args[:doctype] && !DOCTYPES.include?(args[:doctype])
warn "[relaton-ietf] WARNING: invalid doctype #{args[:doctype]}"
Util.warn "WARNING: invalid doctype `#{args[:doctype]}`"
end
@stream = args.delete(:stream)
super
Expand Down
6 changes: 3 additions & 3 deletions lib/relaton_ietf/ietf_bibliography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def search(text)
# reference is required
# @return [RelatonIetf::IetfBibliographicItem] Relaton of reference
def get(code, _year = nil, _opts = {})
warn "[relaton-ietf] (\"#{code}\") fetching..."
Util.warn "(#{code}) fetching..."
result = search code
if result
docid = result.docidentifier.detect(&:primary) || result.docidentifier.first
warn "[relaton-ietf] (\"#{code}\") found #{docid.id}"
Util.warn "(#{code}) found `#{docid.id}`"
else
warn "[relaton-ietf] (\"#{code}\") not found"
Util.warn "(#{code}) not found"
end
result
end
Expand Down
9 changes: 9 additions & 0 deletions lib/relaton_ietf/util.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module RelatonIetf
module Util
extend RelatonBib::Util

def self.logger
RelatonIetf.configuration.logger
end
end
end
2 changes: 1 addition & 1 deletion lib/relaton_ietf/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonIetf
VERSION = "1.16.0".freeze
VERSION = "1.16.1".freeze
end
10 changes: 10 additions & 0 deletions spec/relaton_ietf/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe RelatonIetf do
after { described_class.instance_variable_set :@configuration, nil }

it "configure" do
described_class.configure do |conf|
conf.logger = :logger
end
expect(described_class.configuration.logger).to eq :logger
end
end
2 changes: 1 addition & 1 deletion spec/relaton_ietf/ietf_bibliographic_item_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
it "warn if doctype is invalid" do
expect do
described_class.new doctype: "type"
end.to output(/invalid doctype type/).to_stderr
end.to output(/\[relaton-ietf\] WARNING: invalid doctype `type`/).to_stderr
end

context "render BibXML" do
Expand Down
5 changes: 5 additions & 0 deletions spec/relaton_ietf/util_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe RelatonIetf::Util do
it "#respond_to_missing?" do
expect(described_class.respond_to?(:warn)).to be true
end
end
2 changes: 2 additions & 0 deletions spec/relaton_ietf_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

RSpec.describe RelatonIetf do
before { RelatonIetf.instance_variable_set :@configuration, nil }

it "has a version number" do
expect(RelatonIetf::VERSION).not_to be nil
end
Expand Down
218 changes: 109 additions & 109 deletions spec/vcr_cassettes/non_existed_doc.yml

Large diffs are not rendered by default.

0 comments on commit 14748d5

Please sign in to comment.