relaton 1.18.2 → 1.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/relaton/config.rb +11 -4
  3. data/lib/relaton/db.rb +4 -4
  4. data/lib/relaton/db_cache.rb +2 -1
  5. data/lib/relaton/registry.rb +8 -7
  6. data/lib/relaton/util.rb +1 -4
  7. data/lib/relaton/version.rb +1 -1
  8. data/relaton.gemspec +28 -27
  9. data/spec/relaton/config_spec.rb +2 -2
  10. data/spec/relaton/db_spec.rb +23 -21
  11. data/spec/relaton/registry_spec.rb +38 -2
  12. data/spec/relaton/util_spec.rb +0 -3
  13. data/spec/relaton_spec.rb +11 -2
  14. data/spec/vcr_cassetes/3gpp_tr_00_01u_umts_3_0_0.yml +12201 -11281
  15. data/spec/vcr_cassetes/api_relaton_org.yml +9 -9
  16. data/spec/vcr_cassetes/api_relaton_org_unavailable.yml +14 -14
  17. data/spec/vcr_cassetes/cc_dir_10005_2019.yml +15 -15
  18. data/spec/vcr_cassetes/cie_001_1980.yml +214 -214
  19. data/spec/vcr_cassetes/doi_10_6028_nist_ir_8245.yml +6 -6
  20. data/spec/vcr_cassetes/ecma_6.yml +134 -134
  21. data/spec/vcr_cassetes/en_10160_1999.yml +10060 -10052
  22. data/spec/vcr_cassetes/gb_t_20223_2006.yml +415 -421
  23. data/spec/vcr_cassetes/ieee_528_2019.yml +2158 -2135
  24. data/spec/vcr_cassetes/iso_19115_1.yml +1565 -1281
  25. data/spec/vcr_cassetes/iso_19115_1_2.yml +24 -24
  26. data/spec/vcr_cassetes/iso_19115_1_std.yml +1565 -1281
  27. data/spec/vcr_cassetes/iso_19115_all_parts.yml +11 -11
  28. data/spec/vcr_cassetes/iso_19133_2005.yml +10 -10
  29. data/spec/vcr_cassetes/iso_combined_applied.yml +22 -22
  30. data/spec/vcr_cassetes/iso_combined_included.yml +22 -22
  31. data/spec/vcr_cassetes/iso_dis.yml +10 -10
  32. data/spec/vcr_cassetes/ogc_19_025r1.yml +15 -15
  33. data/spec/vcr_cassetes/omg_ami4ccm_1_0.yml +1203 -1174
  34. data/spec/vcr_cassetes/rfc_8341.yml +136 -134
  35. metadata +70 -56
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e166e4b98b190a6286f8d6ea532e65977a901c2ff5a7f1e26f1ca1412ab92230
4
- data.tar.gz: c07830c2b5f15bef3190b1ea07916731e8befeb9c224c6a1f4749872d8b73285
3
+ metadata.gz: 5a133026bf858511b0385b639ec7cc96ab0f855c31a5446d1d118d009eda235d
4
+ data.tar.gz: b9b89a70476bf01a6c9ca710047ccf13f4531174dafa12e5b37908bdf668d44c
5
5
  SHA512:
6
- metadata.gz: bb61c2add854d65c4113a0130f4ddd562b1bb73aa564897c665334d56dcf7645ad2a22f73a5b081a403e0ea522b22780c0a1ec9fed81905cbc5eee47ca40824e
7
- data.tar.gz: 53633d5bde382e7c57c2af957a1b60b1dbb82fa89cd64d341271b5330c8f634cf8bd3b38527e721fc6ceae8f64fc165bfeb1ef99fb42480ad7cf47c59111ea6c
6
+ metadata.gz: d35962b592b2eb4ed65261bed9638d304bd91ffc09baf1cb40c7e245692381b28d6d4985fe321d326d09770afa738ea3cce1e15ab499501d4221228559051140
7
+ data.tar.gz: 46d9116df1ae0f23d7aea5763908bb4b5ac3ec3073d2bbd8b67578c94b85ab5ab89f327747f420ca2226409955ff78de41a4eeabd7992cb32383491386a45b99
@@ -1,18 +1,25 @@
1
1
  module Relaton
2
2
  module Config
3
- include RelatonBib::Config
3
+ def configure
4
+ yield configuration if block_given?
5
+ end
6
+
7
+ def configuration
8
+ @configuration ||= self::Configuration.new
9
+ end
4
10
  end
5
11
  extend Config
6
12
 
7
- class Configuration < RelatonBib::Configuration
8
- PROGNAME = "relaton".freeze
13
+ class Configuration # < RelatonBib::Configuration
9
14
 
10
15
  attr_accessor :use_api, :api_host
11
16
 
12
17
  def initialize
13
- super
18
+ # super
14
19
  @use_api = false
15
20
  @api_host = "https://api.relaton.org"
16
21
  end
17
22
  end
23
+
24
+ extend Config
18
25
  end
data/lib/relaton/db.rb CHANGED
@@ -112,7 +112,7 @@ module Relaton
112
112
  rescue RelatonBib::RequestError => e
113
113
  args[3].call e
114
114
  rescue StandardError => e
115
- Util.error "ERROR: `#{args[0]}` -- #{e.message}"
115
+ Util.error "`#{args[0]}` -- #{e.message}"
116
116
  args[3].call nil
117
117
  end
118
118
  @queues[stdclass] = { queue: SizedQueue.new(threads * 2), workers_pool: wp }
@@ -435,8 +435,8 @@ module Relaton
435
435
  return fetch_entry(code, year, opts, stdclass, **args) if !entry || opts[:no_cache]
436
436
 
437
437
  if entry&.match?(/^not_found/)
438
- Util.warn "(#{code}) not found in cache, if you wish to " \
439
- "ignore cache please use `no-cache` option."
438
+ Util.info "not found in cache, if you wish to " \
439
+ "ignore cache please use `no-cache` option.", key: code
440
440
  return
441
441
  end
442
442
  entry
@@ -522,7 +522,7 @@ module Relaton
522
522
  next if db.check_version?(fdir)
523
523
 
524
524
  FileUtils.rm_rf(fdir, secure: true)
525
- Util.warn "WARNING: cache #{fdir}: version is obsolete and cache is cleared."
525
+ Util.info "cache #{fdir}: version is obsolete and cache is cleared."
526
526
  end
527
527
  db
528
528
  end
@@ -20,7 +20,7 @@ module Relaton
20
20
  return unless new_dir && @ext == "xml"
21
21
 
22
22
  if File.exist? new_dir
23
- Util.warn "WARNING: target directory exists `#{new_dir}`"
23
+ Util.info "target directory exists `#{new_dir}`"
24
24
  return
25
25
  end
26
26
 
@@ -216,6 +216,7 @@ module Relaton
216
216
  File.open file, File::RDWR | File::CREAT, encoding: "UTF-8" do |f|
217
217
  Timeout.timeout(10) { f.flock File::LOCK_EX }
218
218
  f.write content
219
+ f.flock File::LOCK_UN
219
220
  end
220
221
  end
221
222
  end
@@ -10,7 +10,7 @@ module Relaton
10
10
  relaton_ogc relaton_calconnect relaton_omg relaton_un relaton_w3c
11
11
  relaton_ieee relaton_iho relaton_bipm relaton_ecma relaton_cie relaton_bsi
12
12
  relaton_cen relaton_iana relaton_3gpp relaton_oasis relaton_doi relaton_jis
13
- relaton_xsf relaton_ccsds relaton_etsi relaton_isbn
13
+ relaton_xsf relaton_ccsds relaton_etsi relaton_isbn relaton/plateau
14
14
  ].freeze
15
15
 
16
16
  include Singleton
@@ -30,9 +30,7 @@ module Relaton
30
30
  require "#{b}/processor"
31
31
  register Kernel.const_get "#{camel_case(b)}::Processor"
32
32
  rescue LoadError => e
33
- Util.error("Error: backend #{b} not present")
34
- Util.error("Error: #{e.message}")
35
- Util.error("Error: #{e.backtrace.join "\n"}")
33
+ Util.error "backend #{b} not present\n#{e.message}\n#{e.backtrace.join "\n"}"
36
34
  end
37
35
  end
38
36
 
@@ -97,18 +95,21 @@ module Relaton
97
95
  # @return [Symbol, nil] standard class name
98
96
  #
99
97
  def class_by_ref(ref)
98
+ ref = ref.match(/^\w+\((.*)\)$/) ? Regexp.last_match(1) : ref
100
99
  @processors.each do |class_name, processor|
101
- return class_name if /^(urn:)?#{processor.prefix}(?!\w)/i.match?(ref) ||
100
+ return class_name if /^(urn:)?#{processor.prefix}\b/i.match?(ref) ||
102
101
  processor.defaultprefix.match(ref)
103
102
  end
104
- Util.warn "`#{ref}` does not have a recognised prefix"
103
+ Util.info "`#{ref}` does not have a recognised prefix", key: ref
105
104
  nil
106
105
  end
107
106
 
108
107
  private
109
108
 
110
109
  def camel_case(gem_name)
111
- gem_name.split("_").map(&:capitalize).join
110
+ gem_name.split("/").map do |part|
111
+ part.split("_").map(&:capitalize).join
112
+ end.join("::")
112
113
  end
113
114
  end
114
115
  end
data/lib/relaton/util.rb CHANGED
@@ -1,9 +1,6 @@
1
1
  module Relaton
2
2
  module Util
3
3
  extend RelatonBib::Util
4
-
5
- def self.logger
6
- Relaton.configuration.logger
7
- end
4
+ PROGNAME = "relaton".freeze
8
5
  end
9
6
  end
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "1.18.2".freeze
2
+ VERSION = "1.19.1".freeze
3
3
  end
data/relaton.gemspec CHANGED
@@ -29,31 +29,32 @@ Gem::Specification.new do |spec|
29
29
  # spec.test_files = `git ls-files -- {spec}/*`.split("\n")
30
30
  spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
31
31
 
32
- spec.add_dependency "relaton-3gpp", "~> 1.18.0"
33
- spec.add_dependency "relaton-bipm", "~> 1.18.0"
34
- spec.add_dependency "relaton-bsi", "~> 1.18.1"
35
- spec.add_dependency "relaton-calconnect", "~> 1.18.0"
36
- spec.add_dependency "relaton-ccsds", "~> 1.18.0"
37
- spec.add_dependency "relaton-cen", "~> 1.18.0"
38
- spec.add_dependency "relaton-cie", "~> 1.18.0"
39
- spec.add_dependency "relaton-doi", "~> 1.18.0"
40
- spec.add_dependency "relaton-ecma", "~> 1.18.0"
41
- spec.add_dependency "relaton-etsi", "~> 1.18.0"
42
- spec.add_dependency "relaton-gb", "~> 1.18.2"
43
- spec.add_dependency "relaton-iana", "~> 1.18.0"
44
- spec.add_dependency "relaton-iec", "~> 1.18.0"
45
- spec.add_dependency "relaton-ieee", "~> 1.18.0"
46
- spec.add_dependency "relaton-ietf", "~> 1.18.0"
47
- spec.add_dependency "relaton-iho", "~> 1.18.0"
48
- spec.add_dependency "relaton-isbn", "~> 1.18.0"
49
- spec.add_dependency "relaton-iso", "~> 1.18.4"
50
- spec.add_dependency "relaton-itu", "~> 1.18.0"
51
- spec.add_dependency "relaton-jis", "~> 1.18.0"
52
- spec.add_dependency "relaton-nist", "~> 1.18.0"
53
- spec.add_dependency "relaton-oasis", "~> 1.18.0"
54
- spec.add_dependency "relaton-ogc", "~> 1.18.0"
55
- spec.add_dependency "relaton-omg", "~> 1.18.0"
56
- spec.add_dependency "relaton-un", "~> 1.18.0"
57
- spec.add_dependency "relaton-w3c", "~> 1.18.0"
58
- spec.add_dependency "relaton-xsf", "~> 1.18.0"
32
+ spec.add_dependency "relaton-3gpp", "~> 1.19.0"
33
+ spec.add_dependency "relaton-bipm", "~> 1.19.0"
34
+ spec.add_dependency "relaton-bsi", "~> 1.19.1"
35
+ spec.add_dependency "relaton-calconnect", "~> 1.19.0"
36
+ spec.add_dependency "relaton-ccsds", "~> 1.19.0"
37
+ spec.add_dependency "relaton-cen", "~> 1.19.0"
38
+ spec.add_dependency "relaton-cie", "~> 1.19.0"
39
+ spec.add_dependency "relaton-doi", "~> 1.19.0"
40
+ spec.add_dependency "relaton-ecma", "~> 1.19.0"
41
+ spec.add_dependency "relaton-etsi", "~> 1.19.0"
42
+ spec.add_dependency "relaton-gb", "~> 1.19.0"
43
+ spec.add_dependency "relaton-iana", "~> 1.19.0"
44
+ spec.add_dependency "relaton-iec", "~> 1.19.0"
45
+ spec.add_dependency "relaton-ieee", "~> 1.19.0"
46
+ spec.add_dependency "relaton-ietf", "~> 1.19.0"
47
+ spec.add_dependency "relaton-iho", "~> 1.19.0"
48
+ spec.add_dependency "relaton-isbn", "~> 1.19.0"
49
+ spec.add_dependency "relaton-iso", "~> 1.19.0"
50
+ spec.add_dependency "relaton-itu", "~> 1.19.0"
51
+ spec.add_dependency "relaton-jis", "~> 1.19.0"
52
+ spec.add_dependency "relaton-nist", "~> 1.19.0"
53
+ spec.add_dependency "relaton-oasis", "~> 1.19.0"
54
+ spec.add_dependency "relaton-ogc", "~> 1.19.0"
55
+ spec.add_dependency "relaton-omg", "~> 1.19.0"
56
+ spec.add_dependency "relaton-plateau", "~> 1.19.0"
57
+ spec.add_dependency "relaton-un", "~> 1.19.0"
58
+ spec.add_dependency "relaton-w3c", "~> 1.19.0"
59
+ spec.add_dependency "relaton-xsf", "~> 1.19.0"
59
60
  end
@@ -3,8 +3,8 @@ describe Relaton do
3
3
 
4
4
  it "configure" do
5
5
  described_class.configure do |conf|
6
- conf.logger = :logger
6
+ conf.use_api = true
7
7
  end
8
- expect(described_class.configuration.logger).to eq :logger
8
+ expect(described_class.configuration.use_api).to be true
9
9
  end
10
10
  end
@@ -1,7 +1,14 @@
1
1
  RSpec.describe Relaton::Db do
2
- before(:each) do
3
- Relaton.instance_variable_set :@configuration, nil
2
+ before(:each) do |example|
3
+ # Relaton.instance_variable_set :@configuration, nil
4
4
  FileUtils.rm_rf %w[testcache testcache2]
5
+
6
+ if example.metadata[:vcr]
7
+ # Force to download index file
8
+ require "relaton/index"
9
+ allow_any_instance_of(Relaton::Index::Type).to receive(:actual?).and_return(false)
10
+ allow_any_instance_of(Relaton::Index::FileIO).to receive(:check_file).and_return(nil)
11
+ end
5
12
  end
6
13
 
7
14
  subject { Relaton::Db.new nil, nil }
@@ -28,8 +35,8 @@ RSpec.describe Relaton::Db do
28
35
  expect(subject).to_not receive(:fetch_entry)
29
36
  entry = subject.send :new_bib_entry, "ISO 123", nil, {}, :relaton_iso, db: db, id: "ISO(ISO 123)"
30
37
  expect(entry).to be_nil
31
- end.to output("[relaton] (ISO 123) not found in cache, if you wish " \
32
- "to ignore cache please use `no-cache` option.\n").to_stderr
38
+ end.to output("[relaton] INFO: (ISO 123) not found in cache, if you wish " \
39
+ "to ignore cache please use `no-cache` option.\n").to_stderr_from_any_process
33
40
  end
34
41
 
35
42
  it "ignore cache" do
@@ -125,9 +132,10 @@ RSpec.describe Relaton::Db do
125
132
 
126
133
  it "warn if moving in existed dir" do
127
134
  expect(File).to receive(:exist?).with("new_cache_dir").and_return true
135
+ allow(File).to receive(:exist?).and_call_original
128
136
  expect do
129
137
  expect(db.mv("new_cache_dir")).to be_nil
130
- end.to output(/\[relaton\] WARNING: target directory exists/).to_stderr
138
+ end.to output(/\[relaton\] INFO: target directory exists/).to_stderr_from_any_process
131
139
  end
132
140
 
133
141
  it "clear" do
@@ -221,12 +229,10 @@ RSpec.describe Relaton::Db do
221
229
  expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
222
230
  end
223
231
 
224
- it "when no local db" do
232
+ it "when no local db", vcr: "iso_19115_1" do
225
233
  db = Relaton::Db.new "testcache", nil
226
- VCR.use_cassette "iso_19115_1" do
227
- bib = db.fetch("ISO 19115-1", nil, {})
228
- expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
229
- end
234
+ bib = db.fetch("ISO 19115-1", nil, {})
235
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
230
236
  end
231
237
 
232
238
  it "document with net retries" do
@@ -241,12 +247,10 @@ RSpec.describe Relaton::Db do
241
247
  end
242
248
  end
243
249
 
244
- it "fetch std" do
250
+ it "fetch std", vcr: "iso_19115_1_std" do
245
251
  db = Relaton::Db.new "testcache", nil
246
- VCR.use_cassette "iso_19115_1_std" do
247
- bib = db.fetch_std("ISO 19115-1", nil, :relaton_iso, {})
248
- expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
249
- end
252
+ bib = db.fetch_std("ISO 19115-1", nil, :relaton_iso, {})
253
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
250
254
  end
251
255
 
252
256
  context "async fetch" do
@@ -281,12 +285,10 @@ RSpec.describe Relaton::Db do
281
285
  end
282
286
  end
283
287
 
284
- it "prefix not found" do
288
+ it "prefix not found", vcr: "rfc_unsuccess" do
285
289
  result = ""
286
- VCR.use_cassette "rfc_unsuccess" do
287
- subject.fetch_async("ABC 123456") { |r| queue << r }
288
- Timeout.timeout(5) { result = queue.pop }
289
- end
290
+ subject.fetch_async("ABC 123456") { |r| queue << r }
291
+ Timeout.timeout(5) { result = queue.pop }
290
292
  expect(result).to be_nil
291
293
  end
292
294
 
@@ -299,7 +301,7 @@ RSpec.describe Relaton::Db do
299
301
 
300
302
  it "handle other errors" do
301
303
  expect(subject).to receive(:fetch).and_raise Errno::EACCES
302
- log_io = Relaton.configuration.logger.instance_variable_get(:@logdev)
304
+ log_io = Relaton.logger_pool[:default].instance_variable_get(:@logdev)
303
305
  expect(log_io).to receive(:write).with("[relaton] ERROR: `ISO REF` -- Permission denied\n")
304
306
  subject.fetch_async("ISO REF") { |r| queue << r }
305
307
  result = Timeout.timeout(5) { queue.pop }
@@ -4,8 +4,8 @@ RSpec.describe Relaton::Registry do
4
4
  it "outputs backend not present" do
5
5
  stub_const "Relaton::Registry::SUPPORTED_GEMS", ["not_supported_gem"]
6
6
  expect { Relaton::Registry.clone.instance }.to output(
7
- /backend not_supported_gem not present/,
8
- ).to_stderr
7
+ /\[relaton\] ERROR: backend not_supported_gem not present/,
8
+ ).to_stderr_from_any_process
9
9
  end
10
10
 
11
11
  it "finds ISO processor" do
@@ -127,6 +127,42 @@ RSpec.describe Relaton::Registry do
127
127
  it "ISBN" do
128
128
  expect(Relaton::Registry.instance.by_type("ISBN")).to be_instance_of RelatonIsbn::Processor
129
129
  end
130
+
131
+ context "PLATEAU" do
132
+ let(:processor) { Relaton::Registry.instance.by_type("PLATEAU") }
133
+ before { processor }
134
+
135
+ it "finds processor" do
136
+ expect(processor).to be_instance_of Relaton::Plateau::Processor
137
+ end
138
+
139
+ it "fetch data" do
140
+ expect(Relaton::Plateau::Fetcher).to receive(:fetch).with("plateau-handbooks", output: "dir", format: "xml")
141
+ processor.fetch_data "plateau-handbooks", output: "dir", format: "xml"
142
+ end
143
+
144
+ it "from_xml" do
145
+ expect(Relaton::Plateau::XMLParser).to receive(:from_xml).with(:xml).and_return :bibitem
146
+ expect(processor.from_xml(:xml)).to eq :bibitem
147
+ end
148
+
149
+ it "hash_to_bib" do
150
+ expect(Relaton::Plateau::HashConverter).to receive(:hash_to_bib).with(:hash).and_return bib: :bib
151
+ expect(Relaton::Plateau::BibItem).to receive(:new).with(bib: :bib).and_return :bibitem
152
+ expect(processor.hash_to_bib(:hash)).to eq :bibitem
153
+ end
154
+
155
+ it "grammar_hash" do
156
+ expect(processor.grammar_hash).to be_instance_of String
157
+ end
158
+
159
+ it "remove_index_file" do
160
+ index = double "index"
161
+ expect(index).to receive(:remove_file)
162
+ expect(Relaton::Index).to receive(:find_or_create).and_return index
163
+ processor.remove_index_file
164
+ end
165
+ end
130
166
  end
131
167
 
132
168
  it "find processot by dataset" do
@@ -1,5 +1,2 @@
1
1
  describe Relaton::Util do
2
- it "#respond_to_missing?" do
3
- expect(described_class.respond_to?(:warn)).to be true
4
- end
5
2
  end
data/spec/relaton_spec.rb CHANGED
@@ -7,8 +7,8 @@ RSpec.describe Relaton::Db do
7
7
 
8
8
  it "rejects an illegal reference prefix" do
9
9
  expect { @db.fetch("XYZ XYZ", nil, {}) }.to output(
10
- /does not have a recognised prefix/,
11
- ).to_stderr
10
+ /\[relaton\] INFO: \(XYZ XYZ\) `XYZ XYZ` does not have a recognised prefix/,
11
+ ).to_stderr_from_any_process
12
12
  end
13
13
 
14
14
  context "gets an ISO reference" do
@@ -373,6 +373,15 @@ RSpec.describe Relaton::Db do
373
373
  expect(bib.docidentifier.first.id).to eq "ISBN 978-0-580-50101-4"
374
374
  end
375
375
 
376
+ it "get PLATEAU reference" do
377
+ docid = RelatonBib::DocumentIdentifier.new(id: "PLATEAU Hanbook #01", type: "PLATEAU")
378
+ item = Relaton::Plateau::BibItem.new docid: [docid]
379
+ expect(Relaton::Plateau::Bibliography).to receive(:get).with("PLATEAU Hanbook #01", nil, {}).and_return item
380
+ bib = @db.fetch "PLATEAU Hanbook #01"
381
+ expect(bib).to be_instance_of Relaton::Plateau::BibItem
382
+ expect(bib.docidentifier.first.id).to eq "PLATEAU Hanbook #01"
383
+ end
384
+
376
385
  context "get combined documents" do
377
386
  context "ISO" do
378
387
  it "included" do