relaton 1.12.2 → 1.12.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +1 -19
- data/docs/README.adoc +18 -3
- data/lib/relaton/config.rb +2 -1
- data/lib/relaton/db.rb +72 -32
- data/lib/relaton/db_cache.rb +33 -72
- data/lib/relaton/version.rb +1 -1
- data/lib/relaton.rb +1 -0
- data/spec/relaton/db_cache_spec.rb +2 -2
- data/spec/relaton/registry_spec.rb +1 -1
- data/spec/relaton_spec.rb +38 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/vcr_cassetes/3gpp_tr_00_01u_umts_3_0_0.yml +17 -16
- data/spec/vcr_cassetes/api_relaton_org.yml +56 -0
- data/spec/vcr_cassetes/api_relaton_org_unavailable.yml +194 -0
- data/spec/vcr_cassetes/async_fetch.yml +1278 -1278
- data/spec/vcr_cassetes/bipm_i18n_async_fetch.yml +85 -83
- data/spec/vcr_cassetes/bsi_bs_en_iso_8848.yml +17 -13
- data/spec/vcr_cassetes/cc_dir_10005_2019.yml +14 -12
- data/spec/vcr_cassetes/cie_001_1980.yml +9 -10
- data/spec/vcr_cassetes/ecma_6.yml +10 -10
- data/spec/vcr_cassetes/en_10160_1999.yml +29 -29
- data/spec/vcr_cassetes/fisp_140.yml +6 -6
- data/spec/vcr_cassetes/gb_t_20223_2006.yml +79 -9
- data/spec/vcr_cassetes/iana_service_names_port_numbers.yml +11 -11
- data/spec/vcr_cassetes/iec_60050_102_2007.yml +23 -23
- data/spec/vcr_cassetes/iec_combined_included.yml +87 -87
- data/spec/vcr_cassetes/ieee_528_2019.yml +44 -2202
- data/spec/vcr_cassetes/iho_b_11.yml +10 -10
- data/spec/vcr_cassetes/iso_111111119115_1.yml +4 -4
- data/spec/vcr_cassetes/iso_19115_1.yml +15 -15
- data/spec/vcr_cassetes/iso_19115_1_2.yml +33 -33
- data/spec/vcr_cassetes/iso_19115_all_parts.yml +17 -17
- data/spec/vcr_cassetes/iso_19133_2005.yml +15 -15
- data/spec/vcr_cassetes/iso_combined_applied.yml +31 -31
- data/spec/vcr_cassetes/iso_combined_included.yml +30 -30
- data/spec/vcr_cassetes/iso_dis_14093.yml +16 -16
- data/spec/vcr_cassetes/itu_combined_included.yml +169 -169
- data/spec/vcr_cassetes/oasis_amqp_core_types_v1_0_pt1.yml +10 -10
- data/spec/vcr_cassetes/ogc_19_025r1.yml +7 -7
- data/spec/vcr_cassetes/omg_ami4ccm_1_0.yml +4 -4
- data/spec/vcr_cassetes/rfc_8341.yml +11 -11
- data/spec/vcr_cassetes/sp_800_38b.yml +6 -6
- data/spec/vcr_cassetes/threads_from_env.yml +59 -59
- data/spec/vcr_cassetes/un_rtade_cefact_2004_32.yml +29 -31
- data/spec/vcr_cassetes/w3c_json_ld11.yml +20 -20
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e6ac176313825ccd3328f85d357e92a0316dc40af8174f2af9d021ddf00b4e6
|
4
|
+
data.tar.gz: 031ab61832bdca69327a65aabd6563c80798488e3292fb272420470bd44e1bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db39780d4edf4de3d7d31b150b5a08161c68f9aa62660e0e55d01bde131e997ca3431204e1f4e6db3826c7183a0df032cb09cda57ae998e681535c10d53c0c5b
|
7
|
+
data.tar.gz: bfdb82eb750071772b200ac44d50a5d95019033d4c748483e7bb378b1355c32f8facb0184790da68133dc36018f4386766e6b2739ca9df3d0242e884ba1405ed
|
data/.github/workflows/rake.yml
CHANGED
@@ -10,23 +10,5 @@ on:
|
|
10
10
|
|
11
11
|
jobs:
|
12
12
|
rake:
|
13
|
-
|
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
|
data/lib/relaton/config.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
-
|
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
|
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(
|
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
|
-
|
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
|
-
|
423
|
-
|
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,
|
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
|
-
|
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
|
data/lib/relaton/db_cache.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
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 [
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
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
|
-
|
185
|
-
|
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
|
-
#
|
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
|
data/lib/relaton/version.rb
CHANGED
data/lib/relaton.rb
CHANGED
@@ -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::
|
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
|
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
@@ -23,7 +23,7 @@ http_interactions:
|
|
23
23
|
Connection:
|
24
24
|
- keep-alive
|
25
25
|
Content-Length:
|
26
|
-
- '
|
26
|
+
- '754'
|
27
27
|
Cache-Control:
|
28
28
|
- max-age=300
|
29
29
|
Content-Security-Policy:
|
@@ -31,7 +31,7 @@ http_interactions:
|
|
31
31
|
Content-Type:
|
32
32
|
- text/plain; charset=utf-8
|
33
33
|
Etag:
|
34
|
-
- W/"
|
34
|
+
- W/"bbd7f0c87384dd6862c84526ceedcbe809814a4681ced8f1e2a03507a6d36cf4"
|
35
35
|
Strict-Transport-Security:
|
36
36
|
- max-age=31536000
|
37
37
|
X-Content-Type-Options:
|
@@ -41,29 +41,29 @@ http_interactions:
|
|
41
41
|
X-Xss-Protection:
|
42
42
|
- 1; mode=block
|
43
43
|
X-Github-Request-Id:
|
44
|
-
-
|
44
|
+
- E706:0D55:162F27:183FAB:62E93CAD
|
45
45
|
Accept-Ranges:
|
46
46
|
- bytes
|
47
47
|
Date:
|
48
|
-
-
|
48
|
+
- Tue, 02 Aug 2022 15:03:10 GMT
|
49
49
|
Via:
|
50
50
|
- 1.1 varnish
|
51
51
|
X-Served-By:
|
52
|
-
- cache-
|
52
|
+
- cache-vie6374-VIE
|
53
53
|
X-Cache:
|
54
54
|
- MISS
|
55
55
|
X-Cache-Hits:
|
56
56
|
- '0'
|
57
57
|
X-Timer:
|
58
|
-
-
|
58
|
+
- S1659452590.893199,VS0,VE221
|
59
59
|
Vary:
|
60
60
|
- Authorization,Accept-Encoding,Origin
|
61
61
|
Access-Control-Allow-Origin:
|
62
62
|
- "*"
|
63
63
|
X-Fastly-Request-Id:
|
64
|
-
-
|
64
|
+
- 76ef6b332e38b12c4fefd91589469bd40336b4f5
|
65
65
|
Expires:
|
66
|
-
-
|
66
|
+
- Tue, 02 Aug 2022 15:08:10 GMT
|
67
67
|
Source-Age:
|
68
68
|
- '0'
|
69
69
|
body:
|
@@ -94,12 +94,13 @@ http_interactions:
|
|
94
94
|
- 3rd Generation Partnership Project
|
95
95
|
abbreviation: 3GPP
|
96
96
|
contact:
|
97
|
-
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
- address:
|
98
|
+
street:
|
99
|
+
- c/o ETSI 650, route des Lucioles
|
100
|
+
- 3GPP Mobile Competence Centre
|
101
|
+
city: Sophia Antipolis Cedex
|
102
|
+
country: France
|
103
|
+
postcode: '06921'
|
103
104
|
role:
|
104
105
|
- author
|
105
106
|
- publisher
|
@@ -127,7 +128,7 @@ http_interactions:
|
|
127
128
|
value: withdrawn
|
128
129
|
place:
|
129
130
|
- Sophia Antipolis Cedex, France
|
130
|
-
fetched: '2022-
|
131
|
+
fetched: '2022-07-22'
|
131
132
|
doctype: TR
|
132
133
|
editorialgroup:
|
133
134
|
- name: SMG5
|
@@ -143,5 +144,5 @@ http_interactions:
|
|
143
144
|
freeze_stage3_meeting: SMG-28
|
144
145
|
close_meeting: SP-28
|
145
146
|
project_end: '1999-02-12'
|
146
|
-
recorded_at:
|
147
|
+
recorded_at: Tue, 02 Aug 2022 15:03:10 GMT
|
147
148
|
recorded_with: VCR 6.1.0
|