relaton 1.11.5 → 1.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/lib/relaton/db.rb +51 -28
  3. data/lib/relaton/db_cache.rb +7 -1
  4. data/lib/relaton/version.rb +1 -1
  5. data/relaton.gemspec +21 -21
  6. data/spec/relaton/db_spec.rb +35 -1
  7. data/spec/spec_helper.rb +1 -0
  8. data/spec/vcr_cassetes/3gpp_tr_00_01u_umts_3_0_0.yml +7 -7
  9. data/spec/vcr_cassetes/async_fetch.yml +1402 -1402
  10. data/spec/vcr_cassetes/bipm_i18n_async_fetch.yml +51 -259
  11. data/spec/vcr_cassetes/bsi_bs_en_iso_8848.yml +11 -11
  12. data/spec/vcr_cassetes/cc_dir_10005_2019.yml +10 -10
  13. data/spec/vcr_cassetes/cie_001_1980.yml +10 -9
  14. data/spec/vcr_cassetes/ecma_6.yml +47 -15
  15. data/spec/vcr_cassetes/en_10160_1999.yml +27 -27
  16. data/spec/vcr_cassetes/fisp_140.yml +6 -6
  17. data/spec/vcr_cassetes/gb_t_20223_2006.yml +6 -6
  18. data/spec/vcr_cassetes/iana_service_names_port_numbers.yml +10 -13
  19. data/spec/vcr_cassetes/iec_60050_102_2007.yml +28 -28
  20. data/spec/vcr_cassetes/iec_combined_included.yml +88 -88
  21. data/spec/vcr_cassetes/ieee_528_2019.yml +823 -1133
  22. data/spec/vcr_cassetes/iho_b_11.yml +7 -7
  23. data/spec/vcr_cassetes/iso_111111119115_1.yml +2 -2
  24. data/spec/vcr_cassetes/iso_19115_1.yml +16 -16
  25. data/spec/vcr_cassetes/iso_19115_1_2.yml +29 -29
  26. data/spec/vcr_cassetes/iso_19115_all_parts.yml +15 -15
  27. data/spec/vcr_cassetes/iso_19133_2005.yml +15 -15
  28. data/spec/vcr_cassetes/iso_combined_applied.yml +30 -30
  29. data/spec/vcr_cassetes/iso_combined_included.yml +31 -31
  30. data/spec/vcr_cassetes/iso_dis_14093.yml +14 -14
  31. data/spec/vcr_cassetes/itu_combined_included.yml +168 -168
  32. data/spec/vcr_cassetes/oasis_amqp_core_types_v1_0_pt1.yml +9 -9
  33. data/spec/vcr_cassetes/ogc_19_025r1.yml +7 -7
  34. data/spec/vcr_cassetes/omg_ami4ccm_1_0.yml +4 -4
  35. data/spec/vcr_cassetes/rfc_8341.yml +10 -10
  36. data/spec/vcr_cassetes/sp_800_38b.yml +6 -6
  37. data/spec/vcr_cassetes/threads_from_env.yml +56 -56
  38. data/spec/vcr_cassetes/un_rtade_cefact_2004_32.yml +31 -29
  39. data/spec/vcr_cassetes/w3c_json_ld11.yml +20 -20
  40. metadata +44 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c30099df631e2cbb313f936f4d6a339d9a0767c6d81f3e9523f6013ce95e77a
4
- data.tar.gz: 9413dc9a5806d1b7a997c68298029407a5bc5fb0daa92e8c7f19c66b8b285bd3
3
+ metadata.gz: 9d1245a5e26b3bf22fef51b47397cf229876b56e026e1342a80e3da129c44fad
4
+ data.tar.gz: d13c8549f75408f841ed17f6781d7b33b6cd94586b6e8775928481a045b5c0c1
5
5
  SHA512:
6
- metadata.gz: 33f734e4a386c381de112a99f649c54a586c1367cf91065a693235c8c7252a414a38bffa589de960c3cb4564ab08a0311557c38e08804566ac06a8baf6207de7
7
- data.tar.gz: d0e46c2f6ad5ac0263de42c693db297786b583da4a9b86fe2f3db9f2807e6fdd98c9934ff892d362f1e6a53f2c6cf9a8856b66f405b7fc8270c99f198b9a46b3
6
+ metadata.gz: 7bcdd489f5db390837007665cac0e796ca37e3791b42c9d4eae575b04b30555882b0ad07bb0b9f8cf1c2dec03d9a51a61374a4a9b7c1cc907c9cc6f988ec7a8b
7
+ data.tar.gz: 821809065cd6837638ae14a029f9a6eaad48f9d4cfd1a4d90470e6acd3dbaffa9bc8590fdbb81ed8f9193e91bfe3e7f46bbbb1eee941e7bc8decd7406d3dab54
data/lib/relaton/db.rb CHANGED
@@ -208,7 +208,7 @@ module Relaton
208
208
  end
209
209
 
210
210
  # @param file [String] file path
211
- # @param content [String] content in XML or YAmL format
211
+ # @param content [String] content in XML or YAML format
212
212
  # @param edition [String, nil] edition to filter
213
213
  # @param year [Integer, nil] year to filter
214
214
  # @return [BibliographicItem, nil]
@@ -217,7 +217,7 @@ module Relaton
217
217
  item = if file.match?(/xml$/) then processor.from_xml(content)
218
218
  else processor.hash_to_bib(YAML.safe_load(content))
219
219
  end
220
- item if (edition.nil? || item.edition == edition) && (year.nil? ||
220
+ item if (edition.nil? || item.edition.content == edition) && (year.nil? ||
221
221
  item.date.detect { |d| d.type == "published" && d.on(:year).to_s == year.to_s })
222
222
  end
223
223
 
@@ -305,8 +305,10 @@ module Relaton
305
305
  [prefix, code]
306
306
  end
307
307
 
308
- # @param entry [String] XML string
308
+ #
309
+ # @param entry [String, nil] XML string
309
310
  # @param stdclass [Symbol]
311
+ #
310
312
  # @return [nil, RelatonBib::BibliographicItem,
311
313
  # RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
312
314
  # RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
@@ -316,8 +318,8 @@ module Relaton
316
318
  # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
317
319
  # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
318
320
  def bib_retval(entry, stdclass)
319
- if entry.nil? || entry.match?(/^not_found/) then nil
320
- else @registry.processors[stdclass].from_xml(entry)
321
+ if entry && !entry.match?(/^not_found/)
322
+ @registry.processors[stdclass].from_xml(entry)
321
323
  end
322
324
  end
323
325
 
@@ -346,8 +348,7 @@ module Relaton
346
348
  if db.nil?
347
349
  return if opts[:fetch_db]
348
350
 
349
- bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db,
350
- id: id)
351
+ bibentry = new_bib_entry(searchcode, year, opts, stdclass)
351
352
  return bib_retval(bibentry, stdclass)
352
353
  end
353
354
 
@@ -360,45 +361,61 @@ module Relaton
360
361
  @semaphore.synchronize do
361
362
  db.clone_entry id, altdb if altdb.valid_entry? id, year
362
363
  end
363
- entry = new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id) unless db[id]
364
+ new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
364
365
  @semaphore.synchronize do
365
- db[id] ||= entry
366
366
  altdb.clone_entry(id, db) if !altdb.valid_entry?(id, year)
367
367
  end
368
368
  else
369
369
  return bib_retval(db[id], stdclass) if opts[:fetch_db]
370
370
 
371
- entry = new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id) unless db[id]
372
- @semaphore.synchronize { db[id] ||= entry }
371
+ new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
373
372
  end
374
373
  bib_retval(db[id], stdclass)
375
374
  end
376
375
 
376
+ #
377
+ # Create new bibliographic entry if it doesn't exist in database
378
+ #
377
379
  # @param code [String]
378
380
  # @param year [String]
379
381
  #
380
382
  # @param opts [Hash]
381
- # @option opts [Boolean] :all_parts If all-parts reference is required
382
- # @option opts [Boolean] :keep_year If undated reference should return
383
- # actual reference with year
383
+ # @option opts [Boolean, nil] :all_parts If true then all-parts reference is
384
+ # requested
385
+ # @option opts [Boolean, nil] :keep_year If true then undated reference
386
+ # should return actual reference with year
384
387
  # @option opts [Integer] :retries (1) Number of network retries
385
388
  #
386
389
  # @param stdclass [Symbol]
387
- # @param db [Relaton::DbCache,`NilClass]
388
- # @param id [String] docid
389
- # @return [String]
390
- def new_bib_entry(code, year, opts, stdclass, **args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
390
+ # @param db [Relaton::DbCache,`nil]
391
+ # @param id [String, nil] docid
392
+ #
393
+ # @return [String] bibliographic entry
394
+ # XML or "redirection ID" or "not_found YYYY-MM-DD" string
395
+ #
396
+ def new_bib_entry(code, year, opts, stdclass, **args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
397
+ entry = @semaphore.synchronize { args[:db] && args[:db][args[:id]] }
398
+ if entry
399
+ if entry&.match?(/^not_found/)
400
+ Util.log "[relaton] (#{code}) not found."
401
+ return
402
+ end
403
+ return entry
404
+ end
405
+
391
406
  bib = net_retry(code, year, opts, stdclass, opts.fetch(:retries, 1))
392
407
  bib_id = bib&.docidentifier&.first&.id
393
408
 
394
409
  # when docid doesn't match bib's id then return a reference to bib's id
395
- if args[:db] && args[:id] &&
396
- bib_id && args[:id] !~ %r{#{Regexp.quote("(#{bib_id})")}}
397
- bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
398
- @semaphore.synchronize { args[:db][bid] ||= bib_entry bib }
399
- "redirection #{bid}"
400
- else bib_entry bib
401
- end
410
+ entry = if args[:db] && args[:id] && bib_id && args[:id] !~ %r{#{Regexp.quote("(#{bib_id})")}}
411
+ bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
412
+ @semaphore.synchronize { args[:db][bid] ||= bib_entry bib }
413
+ "redirection #{bid}"
414
+ else bib_entry bib
415
+ end
416
+ return entry if args[:db].nil? || args[:id].nil?
417
+
418
+ @semaphore.synchronize { args[:db][args[:id]] ||= entry }
402
419
  end
403
420
 
404
421
  # @raise [RelatonBib::RequestError]
@@ -454,10 +471,16 @@ module Relaton
454
471
  end
455
472
 
456
473
  class << self
474
+ #
457
475
  # Initialse and return relaton instance, with local and global cache names
458
- # local_cache: local cache name; none created if nil; "relaton" created
459
- # if empty global_cache: boolean to create global_cache
460
- # flush_caches: flush caches
476
+ #
477
+ # @param local_cache [String, nil] local cache name;
478
+ # "relaton" created if empty or nil
479
+ # @param global_cache [Boolean, nil] create global_cache if true
480
+ # @param flush_caches [Boolean, nil] flush caches if true
481
+ #
482
+ # @return [Relaton::Db] relaton DB instance
483
+ #
461
484
  def init_bib_caches(**opts) # rubocop:disable Metrics/CyclomaticComplexity
462
485
  globalname = global_bibliocache_name if opts[:global_cache]
463
486
  localname = local_bibliocache_name(opts[:local_cache])
@@ -45,7 +45,7 @@ module Relaton
45
45
  end
46
46
 
47
47
  prefix_dir = "#{@dir}/#{prefix(key)}"
48
- FileUtils::mkdir_p prefix_dir unless Dir.exist? prefix_dir
48
+ FileUtils::mkdir_p prefix_dir
49
49
  set_version prefix_dir
50
50
  file_safe_write "#{filename(key)}.#{ext(value)}", value
51
51
  end
@@ -72,6 +72,12 @@ module Relaton
72
72
  end
73
73
  end
74
74
 
75
+ #
76
+ # Save entry from cache of `db` to this cache.
77
+ #
78
+ # @param [String] key key of the entry
79
+ # @param [Relaton::Db] db database
80
+ #
75
81
  def clone_entry(key, db)
76
82
  self[key] ||= db.get(key)
77
83
  if (code = redirect? get(key))
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "1.11.5".freeze
2
+ VERSION = "1.12.2".freeze
3
3
  end
data/relaton.gemspec CHANGED
@@ -29,27 +29,27 @@ 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(">= 2.6.0")
31
31
 
32
- spec.add_dependency "relaton-3gpp", "~> 1.11.0"
33
- spec.add_dependency "relaton-bipm", "~> 1.11.0"
34
- spec.add_dependency "relaton-bsi", "~> 1.11.0"
35
- spec.add_dependency "relaton-calconnect", "~> 1.11.0"
36
- spec.add_dependency "relaton-cen", "~> 1.11.0"
37
- spec.add_dependency "relaton-cie", "~> 1.11.0"
38
- spec.add_dependency "relaton-ecma", "~> 1.11.0"
39
- spec.add_dependency "relaton-gb", "~> 1.11.0"
40
- spec.add_dependency "relaton-iana", "~> 1.11.0"
41
- spec.add_dependency "relaton-iec", "~> 1.11.0"
42
- spec.add_dependency "relaton-ieee", "~> 1.11.0"
43
- spec.add_dependency "relaton-ietf", "~> 1.11.0"
44
- spec.add_dependency "relaton-iho", "~> 1.11.0"
45
- spec.add_dependency "relaton-iso", "~> 1.11.0"
46
- spec.add_dependency "relaton-itu", "~> 1.11.0"
47
- spec.add_dependency "relaton-nist", "~> 1.11.0"
48
- spec.add_dependency "relaton-oasis", "~> 1.11.0"
49
- spec.add_dependency "relaton-ogc", "~> 1.11.0"
50
- spec.add_dependency "relaton-omg", "~> 1.11.0"
51
- spec.add_dependency "relaton-un", "~> 1.11.0"
52
- spec.add_dependency "relaton-w3c", "~> 1.11.0"
32
+ spec.add_dependency "relaton-3gpp", "~> 1.12.0"
33
+ spec.add_dependency "relaton-bipm", "~> 1.12.0"
34
+ spec.add_dependency "relaton-bsi", "~> 1.12.0"
35
+ spec.add_dependency "relaton-calconnect", "~> 1.12.0"
36
+ spec.add_dependency "relaton-cen", "~> 1.12.0"
37
+ spec.add_dependency "relaton-cie", "~> 1.12.0"
38
+ spec.add_dependency "relaton-ecma", "~> 1.12.0"
39
+ spec.add_dependency "relaton-gb", "~> 1.12.0"
40
+ spec.add_dependency "relaton-iana", "~> 1.12.0"
41
+ spec.add_dependency "relaton-iec", "~> 1.12.0"
42
+ spec.add_dependency "relaton-ieee", "~> 1.12.0"
43
+ spec.add_dependency "relaton-ietf", "~> 1.12.0"
44
+ spec.add_dependency "relaton-iho", "~> 1.12.0"
45
+ spec.add_dependency "relaton-iso", "~> 1.12.0"
46
+ spec.add_dependency "relaton-itu", "~> 1.12.0"
47
+ spec.add_dependency "relaton-nist", "~> 1.12.0"
48
+ spec.add_dependency "relaton-oasis", "~> 1.12.0"
49
+ spec.add_dependency "relaton-ogc", "~> 1.12.0"
50
+ spec.add_dependency "relaton-omg", "~> 1.12.0"
51
+ spec.add_dependency "relaton-un", "~> 1.12.0"
52
+ spec.add_dependency "relaton-w3c", "~> 1.12.0"
53
53
 
54
54
  spec.add_development_dependency "byebug", "~> 11.0"
55
55
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
@@ -1,6 +1,40 @@
1
1
  RSpec.describe Relaton::Db do
2
2
  before(:each) { FileUtils.rm_rf %w[testcache testcache2] }
3
3
 
4
+ context "instance methods" do
5
+ subject { Relaton::Db.new nil, nil }
6
+
7
+ context "#search_edition_year" do
8
+ it "create bibitem from YAML content" do
9
+ h = { "docid" => [{ "id" => "ISO 123", type: "ISO", "primary" => true }] }
10
+ expect(YAML).to receive(:safe_load).with(:content).and_return h
11
+ item = subject.send :search_edition_year, "iso/item.yaml", :content, nil, nil
12
+ expect(item).to be_instance_of RelatonIsoBib::IsoBibliographicItem
13
+ end
14
+ end
15
+
16
+ context "#new_bib_entry" do
17
+ it "warn if cached entry is not_found" do
18
+ id = "ISO(ISO 123)"
19
+ db = double "db"
20
+ expect(db).to receive(:[]).with(id).and_return "not_found"
21
+ expect do
22
+ entry = subject.send :new_bib_entry, "ISO 123", nil, {}, :relaton_iso, db: db, id: id
23
+ expect(entry).to be_nil
24
+ end.to output("[relaton] (ISO 123) not found.\n").to_stderr
25
+ end
26
+ end
27
+ end
28
+
29
+ context "class methods" do
30
+ it "::init_bib_caches" do
31
+ expect(FileUtils).to receive(:rm_rf).with(/\/\.relaton\/cache$/)
32
+ expect(FileUtils).to receive(:rm_rf).with(/testcache\/cache$/)
33
+ expect(Relaton::Db).to receive(:new).with(/\/\.relaton\/cache$/, /testcache\/cache$/)
34
+ Relaton::Db.init_bib_caches(global_cache: true, local_cache: "testcache", flush_caches: true)
35
+ end
36
+ end
37
+
4
38
  context "modifing database" do
5
39
  let(:db) { Relaton::Db.new "testcache", "testcache2" }
6
40
 
@@ -178,7 +212,7 @@ RSpec.describe Relaton::Db do
178
212
  refs = ["CGPM Resolution 1889-00", "CGPM Résolution 1889-00",
179
213
  "CGPM Réunion 9", "CGPM Meeting 9"]
180
214
  results = []
181
- VCR.use_cassette "bipm_i18n_async_fetch" do
215
+ VCR.use_cassette "bipm_i18n_async_fetch", match_requests_on: %i[method uri body] do
182
216
  refs.each do |ref|
183
217
  db.fetch_async(ref) { |r| queue << [r, ref] }
184
218
  end
data/spec/spec_helper.rb CHANGED
@@ -13,6 +13,7 @@ VCR.configure do |c|
13
13
  clean_outdated_http_interactions: true,
14
14
  re_record_interval: 7 * 24 * 3600,
15
15
  record: :once,
16
+ allow_playback_repeats: true,
16
17
  }
17
18
  c.hook_into :webmock
18
19
  end
@@ -41,29 +41,29 @@ http_interactions:
41
41
  X-Xss-Protection:
42
42
  - 1; mode=block
43
43
  X-Github-Request-Id:
44
- - 7178:6974:A78BC:C192B:62AAF846
44
+ - 7D28:10C50:1BF854C:1DDFC0B:62BDDA6B
45
45
  Accept-Ranges:
46
46
  - bytes
47
47
  Date:
48
- - Thu, 16 Jun 2022 09:30:46 GMT
48
+ - Thu, 30 Jun 2022 17:16:27 GMT
49
49
  Via:
50
50
  - 1.1 varnish
51
51
  X-Served-By:
52
- - cache-vie6334-VIE
52
+ - cache-vie6348-VIE
53
53
  X-Cache:
54
54
  - MISS
55
55
  X-Cache-Hits:
56
56
  - '0'
57
57
  X-Timer:
58
- - S1655371847.568153,VS0,VE230
58
+ - S1656609387.047148,VS0,VE235
59
59
  Vary:
60
60
  - Authorization,Accept-Encoding,Origin
61
61
  Access-Control-Allow-Origin:
62
62
  - "*"
63
63
  X-Fastly-Request-Id:
64
- - da76509a3e570d0b83c3692633c0dfea81acef96
64
+ - 93a267346ed97c52087b05f16495084f70b848e8
65
65
  Expires:
66
- - Thu, 16 Jun 2022 09:35:46 GMT
66
+ - Thu, 30 Jun 2022 17:21:27 GMT
67
67
  Source-Age:
68
68
  - '0'
69
69
  body:
@@ -143,5 +143,5 @@ http_interactions:
143
143
  freeze_stage3_meeting: SMG-28
144
144
  close_meeting: SP-28
145
145
  project_end: '1999-02-12'
146
- recorded_at: Thu, 16 Jun 2022 09:30:46 GMT
146
+ recorded_at: Thu, 30 Jun 2022 17:16:27 GMT
147
147
  recorded_with: VCR 6.1.0