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 7c0e644 commit 2601902
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 45 deletions.
2 changes: 2 additions & 0 deletions lib/relaton_ieee.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_ieee/version"
require "relaton_ieee/config"
require "relaton_ieee/util"
require "relaton_ieee/document_status"
require "relaton_ieee/ieee_bibliography"
require "relaton_ieee/ieee_bibliographic_item"
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_ieee/balloting_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class BallotingGroup
#
def initialize(type:, content:)
unless TYPES.include?(type)
warn "[relaton-ieee] WARNING: type of Balloting group must be one of #{TYPES.join(', ')}"
Util.warn "WARNING: type of Balloting group must be one of `#{TYPES.join('`, `')}`"
end

@type = type
Expand Down
10 changes: 10 additions & 0 deletions lib/relaton_ieee/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module RelatonIeee
module Config
include RelatonBib::Config
end
extend Config

class Configuration < RelatonBib::Configuration
PROGNAME = "relaton-ieee".freeze
end
end
2 changes: 1 addition & 1 deletion lib/relaton_ieee/document_status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Stage < RelatonBib::DocumentStatus::Stage

def initialize(value:, abbreviation: nil)
unless STAGES.include?(value.downcase)
warn "[relaton-ieee] Stage value must be one of #{STAGES.join(', ')}"
Util.warn "Stage value must be one of `#{STAGES.join('`, `')}`"
end
super
end
Expand Down
8 changes: 4 additions & 4 deletions lib/relaton_ieee/ieee_bibliographic_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class IeeeBibliographicItem < RelatonBib::BibliographicItem
#
def initialize(**args) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
if args[:doctype] && !DOCTYPES.include?(args[:doctype])
warn "[relaton-ieee] invalid doctype \"#{args[:doctype]}\". " \
"It should be one of: #{DOCTYPES.join(', ')}."
Util.warn "invalid doctype `#{args[:doctype]}`. " \
"It should be one of: `#{DOCTYPES.join('`, `')}`."
end
if args[:docsubtype] && !SUBTYPES.include?(args[:docsubtype])
warn "[relaton-ieee] invalid docsubtype \"#{args[:docsubtype]}\". " \
"It should be one of: #{SUBTYPES.join(', ')}."
Util.warn "invalid docsubtype `#{args[:docsubtype]}`. " \
"It should be one of: `#{SUBTYPES.join('`, `')}`."
end
eg = args.delete(:editorialgroup)
@trialuse = args.delete(:trialuse)
Expand Down
7 changes: 4 additions & 3 deletions lib/relaton_ieee/ieee_bibliography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ def search(code) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
# if document is found else returns NilClass
#
def get(code, _year = nil, _opts = {}) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
warn "[relaton-ieee] (\"#{code}\") fetching..."
Util.warn "(#{code}) fetching..."
item = search(code)
if item
warn "[relaton-ieee] (\"#{code}\") found #{item.docidentifier.first.id}"
Util.warn "(#{code}) found `#{item.docidentifier.first.id}`"
item
else
warn "[relaton-ieee] (\"#{code}\") not found"
Util.warn "(#{code}) not found"
nil
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/relaton_ieee/rawbib_id_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def parse(normtitle, stdnumber) # rubocop:disable Metrics/AbcSize, Metrics/Metho
PubId.new(publisher: $1, number: $2)

else
warn %{Use stdnumber "#{stdnumber}" for nortitle "#{normtitle}"}
Util.warn %{Use stdnumber "#{stdnumber}" for nortitle "#{normtitle}"}
PubId.new(publisher: "IEEE", number: stdnumber)
end
rescue ArgumentError => e
Expand Down
9 changes: 9 additions & 0 deletions lib/relaton_ieee/util.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module RelatonIeee
module Util
extend RelatonBib::Util

def self.logger
RelatonIeee.configuration.logger
end
end
end
2 changes: 1 addition & 1 deletion lib/relaton_ieee/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RelatonIeee
VERSION = "1.16.0".freeze
VERSION = "1.16.1".freeze
end
2 changes: 1 addition & 1 deletion spec/relaton_ieee/balloting_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
it "warn when type is invalid" do
expect do
described_class.new type: "invalid", content: "Group"
end.to output("[relaton-ieee] WARNING: type of Balloting group must be one of individual, entity\n").to_stderr
end.to output("[relaton-ieee] WARNING: type of Balloting group must be one of `individual`, `entity`\n").to_stderr
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/relaton_ieee/config_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
describe RelatonIeee 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
4 changes: 3 additions & 1 deletion spec/relaton_ieee/document_status_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
describe RelatonIeee::DocumentStatus do
before { RelatonIeee.instance_variable_set :@configuration, nil }

it "warn when stage is invalid" do
expect do
described_class::Stage.new value: "invalid"
end.to output(
"[relaton-ieee] Stage value must be one of draft, approved, superseded, withdrawn\n",
"[relaton-ieee] Stage value must be one of `draft`, `approved`, `superseded`, `withdrawn`\n",
).to_stderr
end
end
9 changes: 5 additions & 4 deletions spec/relaton_ieee/ieee_bibliographic_item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
RSpec.describe RelatonIeee::IeeeBibliographicItem do
let(:type) { "invalid" }
before { RelatonIeee.instance_variable_set :@configuration, nil }

it "returns AsciiBib" do
input = "spec/fixtures/ieee_528_2019.yaml"
Expand All @@ -16,17 +17,17 @@
expect do
described_class.new doctype: type
end.to output(
"[relaton-ieee] invalid doctype \"#{type}\". It should be one of: " \
"guide, recommended-practice, standard, witepaper, redline, other.\n",
"[relaton-ieee] invalid doctype `#{type}`. It should be one of: " \
"`guide`, `recommended-practice`, `standard`, `witepaper`, `redline`, `other`.\n",
).to_stderr
end

it "warn when subdoctype is invalid" do
expect do
described_class.new docsubtype: type
end.to output(
"[relaton-ieee] invalid docsubtype \"#{type}\". It should be one of: " \
"amendment, corrigendum, erratum.\n",
"[relaton-ieee] invalid docsubtype `#{type}`. It should be one of: " \
"`amendment`, `corrigendum`, `erratum`.\n",
).to_stderr
end
end
5 changes: 5 additions & 0 deletions spec/relaton_ieee/util_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe RelatonIeee::Util do
it "#respond_to_missing?" do
expect(described_class.respond_to?(:warn)).to be true
end
end
10 changes: 6 additions & 4 deletions spec/relaton_ieee_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RSpec.describe RelatonIeee do
before { RelatonIeee.instance_variable_set :@configuration, nil }

it "has a version number" do
expect(RelatonIeee::VERSION).not_to be nil
end
Expand Down Expand Up @@ -60,10 +62,10 @@

it "by reference and wrong year" do
VCR.use_cassette "ieee_528" do
# expect do
result = RelatonIeee::IeeeBibliography.get "IEEE 528-2018"
expect(result).to be_nil
# end.to output(/no match found online for IEEE 528 year 2018/).to_stderr
expect do
result = RelatonIeee::IeeeBibliography.get "IEEE 528-2018"
expect(result).to be_nil
end.to output(/\[relaton-ieee\] \(IEEE 528-2018\) not found/).to_stderr
end
end

Expand Down
16 changes: 8 additions & 8 deletions spec/vcr_cassettes/corrigendum.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions spec/vcr_cassettes/ieee_528_2019.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions spec/vcr_cassettes/ieee_std_1619_2007.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2601902

Please sign in to comment.