relaton 1.12.2 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +1 -19
  3. data/docs/README.adoc +18 -3
  4. data/lib/relaton/config.rb +2 -1
  5. data/lib/relaton/db.rb +75 -33
  6. data/lib/relaton/db_cache.rb +33 -72
  7. data/lib/relaton/version.rb +1 -1
  8. data/lib/relaton.rb +1 -0
  9. data/relaton.gemspec +21 -21
  10. data/spec/relaton/db_cache_spec.rb +2 -2
  11. data/spec/relaton/registry_spec.rb +1 -1
  12. data/spec/relaton_spec.rb +38 -1
  13. data/spec/spec_helper.rb +4 -0
  14. data/spec/vcr_cassetes/3gpp_tr_00_01u_umts_3_0_0.yml +17 -16
  15. data/spec/vcr_cassetes/api_relaton_org.yml +56 -0
  16. data/spec/vcr_cassetes/api_relaton_org_unavailable.yml +194 -0
  17. data/spec/vcr_cassetes/async_fetch.yml +1298 -1298
  18. data/spec/vcr_cassetes/bipm_i18n_async_fetch.yml +265 -55
  19. data/spec/vcr_cassetes/bsi_bs_en_iso_8848.yml +29 -28
  20. data/spec/vcr_cassetes/cc_dir_10005_2019.yml +22 -18
  21. data/spec/vcr_cassetes/cie_001_1980.yml +9 -10
  22. data/spec/vcr_cassetes/ecma_6.yml +10 -10
  23. data/spec/vcr_cassetes/en_10160_1999.yml +25 -25
  24. data/spec/vcr_cassetes/fisp_140.yml +6 -6
  25. data/spec/vcr_cassetes/gb_t_20223_2006.yml +79 -9
  26. data/spec/vcr_cassetes/iana_service_names_port_numbers.yml +11 -11
  27. data/spec/vcr_cassetes/iec_60050_102_2007.yml +37 -27
  28. data/spec/vcr_cassetes/iec_combined_included.yml +88 -80
  29. data/spec/vcr_cassetes/ieee_528_2019.yml +45 -2203
  30. data/spec/vcr_cassetes/iho_b_11.yml +10 -10
  31. data/spec/vcr_cassetes/iso_111111119115_1.yml +2 -2
  32. data/spec/vcr_cassetes/iso_19115_1.yml +14 -14
  33. data/spec/vcr_cassetes/iso_19115_1_2.yml +32 -32
  34. data/spec/vcr_cassetes/iso_19115_all_parts.yml +16 -16
  35. data/spec/vcr_cassetes/iso_19133_2005.yml +15 -15
  36. data/spec/vcr_cassetes/iso_combined_applied.yml +30 -30
  37. data/spec/vcr_cassetes/iso_combined_included.yml +30 -30
  38. data/spec/vcr_cassetes/iso_dis_14093.yml +14 -14
  39. data/spec/vcr_cassetes/itu_combined_included.yml +169 -169
  40. data/spec/vcr_cassetes/oasis_amqp_core_types_v1_0_pt1.yml +10 -10
  41. data/spec/vcr_cassetes/ogc_19_025r1.yml +11 -11
  42. data/spec/vcr_cassetes/omg_ami4ccm_1_0.yml +4 -4
  43. data/spec/vcr_cassetes/rfc_8341.yml +12 -15
  44. data/spec/vcr_cassetes/sp_800_38b.yml +6 -6
  45. data/spec/vcr_cassetes/threads_from_env.yml +56 -56
  46. data/spec/vcr_cassetes/un_rtade_cefact_2004_32.yml +29 -31
  47. data/spec/vcr_cassetes/w3c_json_ld11.yml +27 -38
  48. metadata +46 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d1245a5e26b3bf22fef51b47397cf229876b56e026e1342a80e3da129c44fad
4
- data.tar.gz: d13c8549f75408f841ed17f6781d7b33b6cd94586b6e8775928481a045b5c0c1
3
+ metadata.gz: 31661a61a6de1d8269b64bbebe270c5abc32dd9f4aef453a39079d520082e487
4
+ data.tar.gz: 6372e5f8467476af1dd723e7c2f807512eee51c97f9835abce6ae77ce2f7ec9f
5
5
  SHA512:
6
- metadata.gz: 7bcdd489f5db390837007665cac0e796ca37e3791b42c9d4eae575b04b30555882b0ad07bb0b9f8cf1c2dec03d9a51a61374a4a9b7c1cc907c9cc6f988ec7a8b
7
- data.tar.gz: 821809065cd6837638ae14a029f9a6eaad48f9d4cfd1a4d90470e6acd3dbaffa9bc8590fdbb81ed8f9193e91bfe3e7f46bbbb1eee941e7bc8decd7406d3dab54
6
+ metadata.gz: 72cf2b30872b9d37c01697554dddf15a8a44b68d417563a09bb740e8a21ac9079250873b638cf4d8e1ec960d354ba69ca27ef581b31d5fea01beada2398bf7a6
7
+ data.tar.gz: 979c928dc30b43b4baa3475e2daf4e13777f101f2f7cec6872b0f38830a542aeff4eaa3d86be226a2986b1fbc205a8486c75d642d30ffcc257b2e7c32232a0b1
@@ -10,23 +10,5 @@ on:
10
10
 
11
11
  jobs:
12
12
  rake:
13
- name: Test on Ruby ${{ matrix.ruby }} ${{ matrix.os }}
14
- runs-on: ${{ matrix.os }}
15
- continue-on-error: ${{ matrix.experimental }}
16
- strategy:
17
- fail-fast: false
18
- matrix:
19
- ruby: [ '3.0', '2.7', '2.6' ]
20
- os: [ ubuntu-latest, windows-latest, macos-latest ]
21
- experimental: [ false ]
22
- steps:
23
- - uses: actions/checkout@v2
24
- with:
25
- submodules: true
13
+ uses: relaton/support/.github/workflows/rake.yml@master
26
14
 
27
- - uses: ruby/setup-ruby@v1
28
- with:
29
- ruby-version: ${{ matrix.ruby }}
30
- bundler-cache: true
31
-
32
- - run: bundle exec rake
data/docs/README.adoc CHANGED
@@ -62,6 +62,24 @@ e.g. `get("ISO 19115-1", "2014", all_parts: true)` is transformed into a referen
62
62
 
63
63
  == Usage
64
64
 
65
+ === Configuration
66
+
67
+ * `logs` - is array of log levels. Allowed values: `:info`, `:warning`, `:error`, `:debug`. Default values are `[:info, :error]`.
68
+ * `use_api` - `true` if it needs to use an online cache, `false` inf not. Default value is `true`.
69
+ * `api_host` - url of an online cache. Default value is https://api.relaton.org.
70
+
71
+ [source,ruby]
72
+ ----
73
+ require "relaton"
74
+ => true
75
+
76
+ Relaton.configure do |conf|
77
+ conf.logs = %i[info error]
78
+ conf.use_api = true
79
+ conf.api_host = "https://api.relaton.org"
80
+ end
81
+ ----
82
+
65
83
  === Create DB
66
84
 
67
85
  `Relaton::Db#new(globalcache, localcache)` creates new DB. Returns Relaton::Db instance.
@@ -71,9 +89,6 @@ e.g. `get("ISO 19115-1", "2014", all_parts: true)` is transformed into a referen
71
89
 
72
90
  [source,ruby]
73
91
  ----
74
- require "relaton"
75
- => true
76
-
77
92
  # Do not cache any entries retrieved
78
93
  db = Relaton::Db.new(nil, nil)
79
94
  => #<Relaton::Db:0x007faaaba77648
@@ -12,13 +12,14 @@ module Relaton
12
12
  end
13
13
 
14
14
  class Configuration
15
- attr_accessor :logs, :use_api
15
+ attr_accessor :logs, :use_api, :api_host
16
16
 
17
17
  def initialize
18
18
  @logs = %i(info error) # allowed values: :info, :warning, :error, :debug
19
19
 
20
20
  # @TODO change to true when we start using api.relaton.org
21
21
  @use_api = false
22
+ @api_host = "https://api.relaton.org"
22
23
  end
23
24
  end
24
25
 
data/lib/relaton/db.rb CHANGED
@@ -1,10 +1,4 @@
1
- require "yaml"
2
- require_relative "registry"
3
- require_relative "db_cache"
4
-
5
1
  module Relaton
6
- class RelatonError < StandardError; end
7
-
8
2
  class Db
9
3
  # @param global_cache [String] directory of global DB
10
4
  # @param local_cache [String] directory of local DB
@@ -24,10 +18,8 @@ module Relaton
24
18
  # @return [String, nil]
25
19
  def mv(new_dir, type: :global)
26
20
  case type
27
- when :global
28
- @db&.mv new_dir
29
- when :local
30
- @local_db&.mv new_dir
21
+ when :global then @db&.mv new_dir
22
+ when :local then @local_db&.mv new_dir
31
23
  end
32
24
  end
33
25
 
@@ -69,8 +61,7 @@ module Relaton
69
61
  end
70
62
  ref ||= code
71
63
  result = combine_doc ref, year, opts, stdclass
72
- result ||= check_bibliocache(ref, year, opts, stdclass)
73
- result
64
+ result || check_bibliocache(ref, year, opts, stdclass)
74
65
  end
75
66
 
76
67
  # @see Relaton::Db#fetch
@@ -167,11 +158,7 @@ module Relaton
167
158
  # @param key [String]
168
159
  # @return [Hash]
169
160
  def load_entry(key)
170
- unless @local_db.nil?
171
- entry = @local_db[key]
172
- return entry if entry
173
- end
174
- @db[key]
161
+ (@local_db && @local_db[key]) || @db[key]
175
162
  end
176
163
 
177
164
  # @param key [String]
@@ -187,14 +174,52 @@ module Relaton
187
174
  def to_xml
188
175
  db = @local_db || @db || return
189
176
  Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
190
- xml.documents do
191
- xml.parent.add_child db.all.join(" ")
192
- end
177
+ xml.documents { xml.parent.add_child db.all.join(" ") }
193
178
  end.to_xml
194
179
  end
195
180
 
196
181
  private
197
182
 
183
+ # @param (see #fetch_api)
184
+ # @return (see #fetch_api)
185
+ def fetch_doc(code, year, opts, processor)
186
+ if Relaton.configuration.use_api then fetch_api(code, year, opts, processor)
187
+ else processor.get(code, year, opts)
188
+ end
189
+ end
190
+
191
+ #
192
+ # @param code [String]
193
+ # @param year [String]
194
+ #
195
+ # @param opts [Hash]
196
+ # @option opts [Boolean] :all_parts If all-parts reference is required
197
+ # @option opts [Boolean] :keep_year If undated reference should return
198
+ # actual reference with year
199
+ #
200
+ # @param processor [Relaton::Processor]
201
+ # @return [RelatonBib::BibliographicItem, nil]
202
+ def fetch_api(code, year, opts, processor)
203
+ url = "#{Relaton.configuration.api_host}/api/v1/document?#{params(code, year, opts)}"
204
+ rsp = Net::HTTP.get_response URI(url)
205
+ processor.from_xml rsp.body if rsp.code == "200"
206
+ rescue Errno::ECONNREFUSED
207
+ processor.get(code, year, opts)
208
+ end
209
+
210
+ #
211
+ # Make string of parametrs
212
+ #
213
+ # @param [String] code
214
+ # @param [String] year
215
+ # @param [Hash] opts
216
+ #
217
+ # @return [String]
218
+ #
219
+ def params(code, year, opts)
220
+ opts.merge(code: code, year: year).map { |k, v| "#{k}=#{v}" }.join "&"
221
+ end
222
+
198
223
  # @param file [String] file path
199
224
  # @param xml [String] content in XML format
200
225
  # @param text [String, nil] text to serach
@@ -221,9 +246,14 @@ module Relaton
221
246
  item.date.detect { |d| d.type == "published" && d.on(:year).to_s == year.to_s })
222
247
  end
223
248
 
249
+ #
250
+ # Look up text in the XML elements attributes and content
251
+ #
224
252
  # @param xml [String] content in XML format
225
253
  # @param text [String, nil] text to serach
254
+ #
226
255
  # @return [Boolean]
256
+ #
227
257
  def match_xml_text(xml, text)
228
258
  %r{((?<attr>=((?<apstr>')|"))|>).*?#{text}.*?(?(<attr>)(?(<apstr>)'|")|<)}mi.match?(xml)
229
259
  end
@@ -258,10 +288,9 @@ module Relaton
258
288
 
259
289
  doc = @registry.processors[stdclass].hash_to_bib docid: { id: code }
260
290
  ref = refs[0]
261
- updates = check_bibliocache(ref, year, opts, stdclass)
291
+ updates = check_bibliocache(refs[0], year, opts, stdclass)
262
292
  if updates
263
- doc.relation << RelatonBib::DocumentRelation.new(bibitem: updates,
264
- type: "updates")
293
+ doc.relation << RelatonBib::DocumentRelation.new(bibitem: updates, type: "updates")
265
294
  end
266
295
  divider = stdclass == :relaton_itu ? " " : "/"
267
296
  refs[1..].each_with_object(doc) do |c, d|
@@ -403,7 +432,8 @@ module Relaton
403
432
  return entry
404
433
  end
405
434
 
406
- bib = net_retry(code, year, opts, stdclass, opts.fetch(:retries, 1))
435
+ processor = @registry.processors[stdclass]
436
+ bib = net_retry(code, year, opts, processor, opts.fetch(:retries, 1))
407
437
  bib_id = bib&.docidentifier&.first&.id
408
438
 
409
439
  # when docid doesn't match bib's id then return a reference to bib's id
@@ -418,13 +448,27 @@ module Relaton
418
448
  @semaphore.synchronize { args[:db][args[:id]] ||= entry }
419
449
  end
420
450
 
451
+ #
452
+ # @param code [String]
453
+ # @param year [String]
454
+ #
455
+ # @param opts [Hash]
456
+ # @option opts [Boolean] :all_parts If all-parts reference is required
457
+ # @option opts [Boolean] :keep_year If undated reference should return
458
+ # actual reference with year
459
+ #
460
+ # @param processor [Relaton::Processor]
461
+ # @param retries [Integer] remain Number of network retries
462
+ #
421
463
  # @raise [RelatonBib::RequestError]
422
- def net_retry(code, year, opts, stdclass, retries)
423
- @registry.processors[stdclass].get(code, year, opts)
464
+ # @return [RelatonBib::BibliographicItem]
465
+ #
466
+ def net_retry(code, year, opts, processor, retries)
467
+ fetch_doc code, year, opts, processor
424
468
  rescue RelatonBib::RequestError => e
425
469
  raise e unless retries > 1
426
470
 
427
- net_retry(code, year, opts, stdclass, retries - 1)
471
+ net_retry(code, year, opts, processor, retries - 1)
428
472
  end
429
473
 
430
474
  # @param bib [RelatonBib::BibliographicItem,
@@ -437,11 +481,7 @@ module Relaton
437
481
  # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
438
482
  # @return [String] XML or "not_found mm-dd-yyyy"
439
483
  def bib_entry(bib)
440
- if bib.respond_to? :to_xml
441
- bib.to_xml(bibdata: true)
442
- else
443
- "not_found #{Date.today}"
444
- end
484
+ bib.respond_to?(:to_xml) ? bib.to_xml(bibdata: true) : "not_found #{Date.today}"
445
485
  end
446
486
 
447
487
  # @param dir [String, nil] DB directory
@@ -500,7 +540,9 @@ module Relaton
500
540
  end
501
541
 
502
542
  def local_bibliocache_name(cachename)
503
- cachename = "relaton" if cachename.nil? || cachename.empty?
543
+ return nil if cachename.nil?
544
+
545
+ cachename = "relaton" if cachename.empty?
504
546
  "#{cachename}/cache"
505
547
  end
506
548
  end
@@ -10,9 +10,7 @@ module Relaton
10
10
  def initialize(dir, ext = "xml")
11
11
  @dir = dir
12
12
  @ext = ext
13
- FileUtils::mkdir_p @dir
14
- # file_version = "#{@dir}/version"
15
- # set_version # unless File.exist? file_version
13
+ FileUtils::mkdir_p dir
16
14
  end
17
15
 
18
16
  # Move caches to anothe dir
@@ -102,10 +100,10 @@ module Relaton
102
100
 
103
101
  # Returns all items
104
102
  # @return [Array<String>]
105
- def all
103
+ def all(&block)
106
104
  Dir.glob("#{@dir}/**/*.{xml,yml,yaml}").sort.map do |f|
107
105
  content = File.read(f, encoding: "utf-8")
108
- block_given? ? yield(f, content) : content
106
+ block ? yield(f, content) : content
109
107
  end
110
108
  end
111
109
 
@@ -113,30 +111,19 @@ module Relaton
113
111
  # @param key [String]
114
112
  def delete(key)
115
113
  file = filename key
116
- f = search_ext(file)
114
+ f = search_ext file
117
115
  File.delete f if f
118
116
  end
119
117
 
120
118
  # Check if version of the DB match to the gem grammar hash.
121
119
  # @param fdir [String] dir pathe to flover cache
122
- # @return [TrueClass, FalseClass]
120
+ # @return [Boolean]
123
121
  def check_version?(fdir)
124
122
  version_dir = "#{fdir}/version"
125
123
  return false unless File.exist? version_dir
126
124
 
127
125
  v = File.read version_dir, encoding: "utf-8"
128
- v.strip == grammar_hash(fdir)
129
- end
130
-
131
- # Set version of the DB to the gem grammar hash.
132
- # @param fdir [String] dir pathe to flover cache
133
- # @return [Relaton::DbCache]
134
- def set_version(fdir)
135
- file_version = "#{fdir}/version"
136
- unless File.exist? file_version
137
- file_safe_write file_version, grammar_hash(fdir)
138
- end
139
- self
126
+ v.strip == self.class.grammar_hash(fdir)
140
127
  end
141
128
 
142
129
  # if cached reference is undated, expire it after 60 days
@@ -150,15 +137,6 @@ module Relaton
150
137
  year || Date.today - date < 60
151
138
  end
152
139
 
153
- protected
154
-
155
- # @param fdir [String] dir pathe to flover cache
156
- # @return [String]
157
- def grammar_hash(fdir)
158
- type = fdir.split("/").last
159
- Relaton::Registry.instance.by_type(type)&.grammar_hash
160
- end
161
-
162
140
  # Reads file by a key
163
141
  #
164
142
  # @param key [String]
@@ -170,19 +148,16 @@ module Relaton
170
148
  File.read(f, encoding: "utf-8")
171
149
  end
172
150
 
173
- private
174
-
175
- # Check if a file content is redirection
176
- #
177
- # @prarm value [String] file content
178
- # @return [String, NilClass] redirection code or nil
179
- def redirect?(value)
180
- %r{redirection\s(?<code>.*)} =~ value
181
- code
151
+ # @param fdir [String] dir pathe to flover cache
152
+ # @return [String]
153
+ def self.grammar_hash(fdir)
154
+ type = fdir.split("/").last
155
+ Relaton::Registry.instance.by_type(type)&.grammar_hash
182
156
  end
183
157
 
184
- # Return item's file name
185
- # @param key [String]
158
+ private
159
+
160
+ # @param value [String]
186
161
  # @return [String]
187
162
  def filename(key)
188
163
  prefcode = key.downcase.match(/^(?<prefix>[^(]+)\((?<code>[^)]+)/)
@@ -210,13 +185,31 @@ module Relaton
210
185
  end
211
186
  end
212
187
 
213
- # Return item's subdir
188
+ # Set version of the DB to the gem grammar hash.
189
+ # @param fdir [String] dir pathe to flover cache
190
+ def set_version(fdir)
191
+ file_version = "#{fdir}/version"
192
+ unless File.exist? file_version
193
+ file_safe_write file_version, self.class.grammar_hash(fdir)
194
+ end
195
+ end
196
+
197
+ # Return item's file name
214
198
  # @param key [String]
215
199
  # @return [String]
216
200
  def prefix(key)
217
201
  key.downcase.match(/^[^(]+(?=\()/).to_s
218
202
  end
219
203
 
204
+ # Check if a file content is redirection
205
+ #
206
+ # @prarm value [String] file content
207
+ # @return [String, NilClass] redirection code or nil
208
+ def redirect?(value)
209
+ %r{redirection\s(?<code>.*)} =~ value
210
+ code
211
+ end
212
+
220
213
  # @param file [String]
221
214
  # @content [String]
222
215
  def file_safe_write(file, content)
@@ -225,37 +218,5 @@ module Relaton
225
218
  f.write content
226
219
  end
227
220
  end
228
-
229
- class << self
230
- private
231
-
232
- def global_bibliocache_name
233
- "#{Dir.home}/.relaton/cache"
234
- end
235
-
236
- def local_bibliocache_name(cachename)
237
- return nil if cachename.nil?
238
-
239
- cachename = "relaton" if cachename.empty?
240
- "#{cachename}/cache"
241
- end
242
-
243
- public
244
-
245
- # Initialse and return relaton instance, with local and global cache names
246
- # local_cache: local cache name; none created if nil; "relaton" created
247
- # if empty global_cache: boolean to create global_cache
248
- # flush_caches: flush caches
249
- def init_bib_caches(opts) # rubocop:disable Metrics/CyclomaticComplexity
250
- globalname = global_bibliocache_name if opts[:global_cache]
251
- localname = local_bibliocache_name(opts[:local_cache])
252
- localname = "relaton" if localname&.empty?
253
- if opts[:flush_caches]
254
- FileUtils.rm_rf globalname unless globalname.nil?
255
- FileUtils.rm_rf localname unless localname.nil?
256
- end
257
- Relaton::Db.new(globalname, localname)
258
- end
259
- end
260
221
  end
261
222
  end
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "1.12.2".freeze
2
+ VERSION = "1.13.0".freeze
3
3
  end
data/lib/relaton.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "relaton/util"
2
2
  require "relaton/config"
3
+ require "yaml"
3
4
 
4
5
  require "relaton/workers_pool"
5
6
  require "relaton/db"
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.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"
32
+ spec.add_dependency "relaton-3gpp", "~> 1.13.0"
33
+ spec.add_dependency "relaton-bipm", "~> 1.13.0"
34
+ spec.add_dependency "relaton-bsi", "~> 1.13.0"
35
+ spec.add_dependency "relaton-calconnect", "~> 1.13.0"
36
+ spec.add_dependency "relaton-cen", "~> 1.13.0"
37
+ spec.add_dependency "relaton-cie", "~> 1.13.0"
38
+ spec.add_dependency "relaton-ecma", "~> 1.13.0"
39
+ spec.add_dependency "relaton-gb", "~> 1.13.0"
40
+ spec.add_dependency "relaton-iana", "~> 1.13.0"
41
+ spec.add_dependency "relaton-iec", "~> 1.13.0"
42
+ spec.add_dependency "relaton-ieee", "~> 1.13.0"
43
+ spec.add_dependency "relaton-ietf", "~> 1.13.0"
44
+ spec.add_dependency "relaton-iho", "~> 1.13.0"
45
+ spec.add_dependency "relaton-iso", "~> 1.13.0"
46
+ spec.add_dependency "relaton-itu", "~> 1.13.0"
47
+ spec.add_dependency "relaton-nist", "~> 1.13.0"
48
+ spec.add_dependency "relaton-oasis", "~> 1.13.0"
49
+ spec.add_dependency "relaton-ogc", "~> 1.13.0"
50
+ spec.add_dependency "relaton-omg", "~> 1.13.0"
51
+ spec.add_dependency "relaton-un", "~> 1.13.0"
52
+ spec.add_dependency "relaton-w3c", "~> 1.13.0"
53
53
 
54
54
  spec.add_development_dependency "byebug", "~> 11.0"
55
55
  spec.add_development_dependency "equivalent-xml", "~> 0.6"
@@ -6,8 +6,8 @@ RSpec.describe Relaton::DbCache do
6
6
  cache_path = File.expand_path("~/.relaton/cache")
7
7
  FileUtils.mv cache_path, "relaton1/cache", force: true
8
8
  FileUtils.rm_rf %w(relaton)
9
- Relaton::DbCache.init_bib_caches(
10
- global_cache: true, local_cache: "", flush_caches: true
9
+ Relaton::Db.init_bib_caches(
10
+ global_cache: true, local_cache: "", flush_caches: true,
11
11
  )
12
12
  expect(File.exist?(cache_path)).to be true
13
13
  expect(File.exist?("relaton")).to be true
@@ -2,7 +2,7 @@ RSpec.describe Relaton::Registry do
2
2
  it "outputs backend not present" do
3
3
  stub_const "Relaton::Registry::SUPPORTED_GEMS", ["not_supported_gem"]
4
4
  expect { Relaton::Registry.clone.instance }.to output(
5
- /backend not_supported_gem not present/
5
+ /backend not_supported_gem not present/,
6
6
  ).to_stderr
7
7
  end
8
8
 
data/spec/relaton_spec.rb CHANGED
@@ -214,6 +214,9 @@ RSpec.describe Relaton::Db do
214
214
  .at_most :once
215
215
  allow(File).to receive(:write).and_call_original
216
216
  VCR.use_cassette "ogc_19_025r1" do
217
+ expect(File).to receive(:exist?).with("/Users/andrej/.relaton/ogc/bibliography.json").and_return(false).at_most :once
218
+ expect(File).to receive(:exist?).with("/Users/andrej/.relaton/ogc/etag.txt").and_return(false).at_most :once
219
+ allow(File).to receive(:exist?).and_call_original
217
220
  bib = @db.fetch "OGC 19-025r1", nil, {}
218
221
  expect(bib).to be_instance_of RelatonOgc::OgcBibliographicItem
219
222
  end
@@ -396,7 +399,7 @@ RSpec.describe Relaton::Db do
396
399
  context "version control" do
397
400
  before(:each) { @db.save_entry "iso(test_key)", "<bibitem><title>test_value</title></bibitem>" }
398
401
 
399
- it "shoudn't clear cacho if version isn't changed" do
402
+ it "shoudn't clear cache if version isn't changed" do
400
403
  testcache = @db.instance_variable_get :@db
401
404
  expect(testcache.all).to be_any
402
405
  testcache = @db.instance_variable_get :@local_db
@@ -414,4 +417,38 @@ RSpec.describe Relaton::Db do
414
417
  expect(File.exist?("testcache2/iso/version")).to eq false
415
418
  end
416
419
  end
420
+
421
+ context "api.relaton.org" do
422
+ before(:each) do
423
+ Relaton.configure do |config|
424
+ config.use_api = true
425
+ # config.api_host = "http://0.0.0.0:9292"
426
+ end
427
+ end
428
+
429
+ after(:each) do
430
+ Relaton.configure do |config|
431
+ config.use_api = false
432
+ end
433
+ end
434
+
435
+ it "get document" do
436
+ VCR.use_cassette "api_relaton_org" do
437
+ bib = @db.fetch "ISO 19115-2", "2019"
438
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
439
+ end
440
+ end
441
+
442
+ it "if unavailable then get document directly" do
443
+ expect(Net::HTTP).to receive(:get_response).and_wrap_original do |m, *args|
444
+ raise Errno::ECONNREFUSED if args[0].host == "api.relaton.org"
445
+
446
+ m.call(*args)
447
+ end.at_least :once
448
+ VCR.use_cassette "api_relaton_org_unavailable" do
449
+ bib = @db.fetch "ISO 19115-2", "2019"
450
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
451
+ end
452
+ end
453
+ end
417
454
  end
data/spec/spec_helper.rb CHANGED
@@ -24,6 +24,10 @@ end
24
24
 
25
25
  require "relaton"
26
26
 
27
+ Relaton.configure do |config|
28
+ config.use_api = false
29
+ end
30
+
27
31
  RSpec.configure do |config|
28
32
  # Enable flags like --only-failures and --next-failure
29
33
  config.example_status_persistence_file_path = ".rspec_status"