relaton 1.12.0 → 1.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/lib/relaton/db.rb +45 -27
  3. data/lib/relaton/db_cache.rb +7 -1
  4. data/lib/relaton/version.rb +1 -1
  5. data/spec/relaton/db_spec.rb +34 -0
  6. data/spec/vcr_cassetes/3gpp_tr_00_01u_umts_3_0_0.yml +7 -7
  7. data/spec/vcr_cassetes/async_fetch.yml +1343 -1343
  8. data/spec/vcr_cassetes/bsi_bs_en_iso_8848.yml +10 -10
  9. data/spec/vcr_cassetes/cc_dir_10005_2019.yml +8 -8
  10. data/spec/vcr_cassetes/cie_001_1980.yml +10 -9
  11. data/spec/vcr_cassetes/ecma_6.yml +47 -16
  12. data/spec/vcr_cassetes/en_10160_1999.yml +27 -27
  13. data/spec/vcr_cassetes/fisp_140.yml +6 -6
  14. data/spec/vcr_cassetes/gb_t_20223_2006.yml +6 -6
  15. data/spec/vcr_cassetes/iana_service_names_port_numbers.yml +10 -13
  16. data/spec/vcr_cassetes/iec_60050_102_2007.yml +33 -43
  17. data/spec/vcr_cassetes/iec_combined_included.yml +95 -105
  18. data/spec/vcr_cassetes/ieee_528_2019.yml +1164 -1485
  19. data/spec/vcr_cassetes/iho_b_11.yml +7 -7
  20. data/spec/vcr_cassetes/iso_111111119115_1.yml +2 -2
  21. data/spec/vcr_cassetes/iso_19115_1.yml +13 -13
  22. data/spec/vcr_cassetes/iso_19115_1_2.yml +25 -25
  23. data/spec/vcr_cassetes/iso_19115_all_parts.yml +12 -12
  24. data/spec/vcr_cassetes/iso_19133_2005.yml +13 -13
  25. data/spec/vcr_cassetes/iso_combined_applied.yml +27 -27
  26. data/spec/vcr_cassetes/iso_combined_included.yml +28 -28
  27. data/spec/vcr_cassetes/iso_dis_14093.yml +14 -14
  28. data/spec/vcr_cassetes/itu_combined_included.yml +168 -168
  29. data/spec/vcr_cassetes/oasis_amqp_core_types_v1_0_pt1.yml +9 -9
  30. data/spec/vcr_cassetes/ogc_19_025r1.yml +7 -7
  31. data/spec/vcr_cassetes/omg_ami4ccm_1_0.yml +4 -4
  32. data/spec/vcr_cassetes/rfc_8341.yml +11 -11
  33. data/spec/vcr_cassetes/sp_800_38b.yml +6 -6
  34. data/spec/vcr_cassetes/threads_from_env.yml +59 -59
  35. data/spec/vcr_cassetes/un_rtade_cefact_2004_32.yml +31 -29
  36. data/spec/vcr_cassetes/w3c_json_ld11.yml +19 -19
  37. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb0eb1b1516d3d9891e873ecad6e439da21cb0cf0ef1b13d9f0a53568b04ad6d
4
- data.tar.gz: af692237538c88b588db7537366d0fbc476e92e60f48163f892f0cb254c1fa2d
3
+ metadata.gz: 8299cf7ea6a28e344f438461d16233fe9acd733bc00441583ce9768c702b15fa
4
+ data.tar.gz: 28d87384bb3b763981ae98902b144236254b7cce20c3d608ef746be679b0661a
5
5
  SHA512:
6
- metadata.gz: 771e6695638f73ee4c6bb4c00d376889ecd5b7120cd9f31e055ab06f3060b24b55e3276f90d74909806b5977f54593cabc201a17729922e2589e5ac1c0fe6ea4
7
- data.tar.gz: 2e9611d5f1b99206a2c99f42720638321781563109e9b0e01345c9576dd6bbd9836c185b55233ea6d7c7ddeaf7c86d90a00605a52ba12d6f9527b7c9a6df5cc0
6
+ metadata.gz: 5720aed26b5585b6673d92fd8c99fbae0883689c254344d5dbad5549a157388bd6422a2550942eb58a8d32f1c2d0aeafd6485de55274c0c02271ec5f87661405
7
+ data.tar.gz: 45fca34e30fe15699b9b3933f4060c877d54947ae31c5bc70ff05812b654c0876175eedda1d71ef16755a4db02a797c30199cd2128d081ae46b186a4939964f5
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]
@@ -305,8 +305,10 @@ module Relaton
305
305
  [prefix, code]
306
306
  end
307
307
 
308
+ #
308
309
  # @param entry [String] 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,9 +318,7 @@ 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
- end
321
+ @registry.processors[stdclass].from_xml(entry) if entry
322
322
  end
323
323
 
324
324
  # @param code [String]
@@ -346,8 +346,7 @@ module Relaton
346
346
  if db.nil?
347
347
  return if opts[:fetch_db]
348
348
 
349
- bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db,
350
- id: id)
349
+ bibentry = new_bib_entry(searchcode, year, opts, stdclass)
351
350
  return bib_retval(bibentry, stdclass)
352
351
  end
353
352
 
@@ -360,45 +359,58 @@ module Relaton
360
359
  @semaphore.synchronize do
361
360
  db.clone_entry id, altdb if altdb.valid_entry? id, year
362
361
  end
363
- entry = new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id) unless db[id]
362
+ new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
364
363
  @semaphore.synchronize do
365
- db[id] ||= entry
366
364
  altdb.clone_entry(id, db) if !altdb.valid_entry?(id, year)
367
365
  end
368
366
  else
369
367
  return bib_retval(db[id], stdclass) if opts[:fetch_db]
370
368
 
371
- entry = new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id) unless db[id]
372
- @semaphore.synchronize { db[id] ||= entry }
369
+ new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
373
370
  end
374
371
  bib_retval(db[id], stdclass)
375
372
  end
376
373
 
374
+ #
375
+ # Create new bibliographic entry if it doesn't exist in database
376
+ #
377
377
  # @param code [String]
378
378
  # @param year [String]
379
379
  #
380
380
  # @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
381
+ # @option opts [Boolean, nil] :all_parts If true then all-parts reference is
382
+ # requested
383
+ # @option opts [Boolean, nil] :keep_year If true then undated reference
384
+ # should return actual reference with year
384
385
  # @option opts [Integer] :retries (1) Number of network retries
385
386
  #
386
387
  # @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
388
+ # @param db [Relaton::DbCache,`nil]
389
+ # @param id [String, nil] docid
390
+ #
391
+ # @return [String] bibliographic entry
392
+ # XML or "redirection ID" or "not_found YYYY-MM-DD" string
393
+ #
394
+ def new_bib_entry(code, year, opts, stdclass, **args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
395
+ entry = @semaphore.synchronize { args[:db] && args[:db][args[:id]] }
396
+ if entry
397
+ Util.log "[relaton] (#{code}) not found." if entry&.match?(/^not_found/)
398
+ return entry
399
+ end
400
+
391
401
  bib = net_retry(code, year, opts, stdclass, opts.fetch(:retries, 1))
392
402
  bib_id = bib&.docidentifier&.first&.id
393
403
 
394
404
  # 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
405
+ entry = if args[:db] && args[:id] && bib_id && args[:id] !~ %r{#{Regexp.quote("(#{bib_id})")}}
406
+ bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
407
+ @semaphore.synchronize { args[:db][bid] ||= bib_entry bib }
408
+ "redirection #{bid}"
409
+ else bib_entry bib
410
+ end
411
+ return entry if args[:db].nil? || args[:id].nil?
412
+
413
+ @semaphore.synchronize { args[:db][args[:id]] ||= entry }
402
414
  end
403
415
 
404
416
  # @raise [RelatonBib::RequestError]
@@ -454,10 +466,16 @@ module Relaton
454
466
  end
455
467
 
456
468
  class << self
469
+ #
457
470
  # 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
471
+ #
472
+ # @param local_cache [String, nil] local cache name;
473
+ # "relaton" created if empty or nil
474
+ # @param global_cache [Boolean, nil] create global_cache if true
475
+ # @param flush_caches [Boolean, nil] flush caches if true
476
+ #
477
+ # @return [Relaton::Db] relaton DB instance
478
+ #
461
479
  def init_bib_caches(**opts) # rubocop:disable Metrics/CyclomaticComplexity
462
480
  globalname = global_bibliocache_name if opts[:global_cache]
463
481
  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.12.0".freeze
2
+ VERSION = "1.12.1".freeze
3
3
  end
@@ -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 eq "not_found"
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
 
@@ -41,29 +41,29 @@ http_interactions:
41
41
  X-Xss-Protection:
42
42
  - 1; mode=block
43
43
  X-Github-Request-Id:
44
- - 8632:A505:57A7C:6013A:62B49FA8
44
+ - 7D28:10C50:1BF854C:1DDFC0B:62BDDA6B
45
45
  Accept-Ranges:
46
46
  - bytes
47
47
  Date:
48
- - Thu, 23 Jun 2022 17:15:20 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-vie6363-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
- - S1656004520.417992,VS0,VE231
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
- - e165b70d2170479617e6f38ce302ae4e577caea3
64
+ - 93a267346ed97c52087b05f16495084f70b848e8
65
65
  Expires:
66
- - Thu, 23 Jun 2022 17:20:20 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, 23 Jun 2022 17:15:20 GMT
146
+ recorded_at: Thu, 30 Jun 2022 17:16:27 GMT
147
147
  recorded_with: VCR 6.1.0