relaton-index 0.2.14 → 0.2.16

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 074e4a9ad24460b1c4ae2b34bfbfe37e0674e204517d5137665b47ade1296295
4
- data.tar.gz: 6b8df9730b13c94331942d2ed21f7ea27673d47e5e6fe4d9d4099e919a17de47
3
+ metadata.gz: 4108f8054c21d68ee61c745be7a61c9d35f1dfdc054b1bf3a98b0d3d4bbe7ce1
4
+ data.tar.gz: 765718355ee7cb6182ef08513a2235be8efc45b4e2b086585c9ba6d7c7ff2006
5
5
  SHA512:
6
- metadata.gz: d014942345f4a0b208390fd2e1404c630acdc6c7112175883850a8a1118750565be104625fe1b0c470e92c55ac3ae1357a1b487f131cc2d515ed14b959e38641
7
- data.tar.gz: 0cde39c9290fb2c7267aa8c5f9d61433eef2bdbbf5e17829d45921bada82feedba109532b2d08a28b117d1b0177acba54335b27d82e4792de4d205c6cf577693
6
+ metadata.gz: 33a29690bd1296f6c44358a513d016ab433a34f89de508466d919b22a76f834d077a6fb5fb69579b694fcfd440458e53dd5931943c3bd8cb12d4f725509fe265
7
+ data.tar.gz: 1f23d97956f434d7ceb76688da5086e7ee545c7685455f9964ece8db783f326f591a5d4ef984694ce09ee0cd6786fb63d8f24eff06875fc51157985bf8cfef63
@@ -106,12 +106,7 @@ module Relaton
106
106
  yaml = Index.config.storage.read(file)
107
107
  return unless yaml
108
108
 
109
- index = YAML.safe_load yaml, permitted_classes: [Symbol]
110
- return deserialize_pubid(index) if check_format index
111
-
112
- warn_local_index_error "Wrong structure of the"
113
- rescue Psych::SyntaxError
114
- warn_local_index_error "YAML parsing error when reading"
109
+ load_index(yaml) || []
115
110
  end
116
111
 
117
112
  def deserialize_pubid(index)
@@ -134,6 +129,23 @@ module Relaton
134
129
  @progname ||= "relaton-#{@dir}"
135
130
  end
136
131
 
132
+ def load_index(yaml, save = false)
133
+ index = YAML.safe_load(yaml, permitted_classes: [Symbol])
134
+ save index if save
135
+ return deserialize_pubid(index) if check_format index
136
+
137
+ if save
138
+ warn_remote_index_error "Wrong structure of"
139
+ else
140
+ warn_local_index_error "Wrong structure of"
141
+ end
142
+ rescue Psych::SyntaxError
143
+ if save
144
+ warn_remote_index_error "YAML parsing error when reading"
145
+ else
146
+ warn_local_index_error "YAML parsing error when reading"
147
+ end
148
+ end
137
149
  #
138
150
  # Fetch index from external repository and save it to storage
139
151
  #
@@ -144,14 +156,8 @@ module Relaton
144
156
  zip = Zip::InputStream.new resp
145
157
  entry = zip.get_next_entry
146
158
  yaml = entry.get_input_stream.read
147
- index = YAML.safe_load(yaml, permitted_classes: [Symbol])
148
- save index
149
159
  Util.info "Downloaded index from `#{url}`", progname
150
- return index if check_format index
151
-
152
- warn_remote_index_error "Wrong structure of"
153
- rescue Psych::SyntaxError
154
- warn_remote_index_error "YAML parsing error when reading"
160
+ load_index(yaml, save = true)
155
161
  end
156
162
 
157
163
  def warn_remote_index_error(reason)
@@ -22,7 +22,7 @@ module Relaton
22
22
  if @pool[type.upcase.to_sym]&.actual?(**args)
23
23
  @pool[type.upcase.to_sym]
24
24
  else
25
- @pool[type.upcase.to_sym] = Type.new(type, args[:url], args[:file], args[:id_keys])
25
+ @pool[type.upcase.to_sym] = Type.new(type, args[:url], args[:file], args[:id_keys], args[:pubid_class])
26
26
  end
27
27
  end
28
28
 
@@ -80,7 +80,7 @@ module Relaton
80
80
  # @return [void]
81
81
  #
82
82
  def save
83
- @file_io.save @index
83
+ @file_io.save(@index || [])
84
84
  end
85
85
 
86
86
  #
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Relaton
4
4
  module Index
5
- VERSION = "0.2.14"
5
+ VERSION = "0.2.16"
6
6
  end
7
7
  end
data/lib/relaton/index.rb CHANGED
@@ -19,17 +19,10 @@ module Relaton
19
19
 
20
20
  class << self
21
21
  #
22
- # Find or create index
22
+ # Proxy for Pool#type
23
23
  #
24
- # @param [String] type index type (ISO, IEC, etc.)
25
- # @param [String, nil] url external URL to index, used to fetch index for searching files
26
- # @param [String, nil] file output file name, default is config.filename
27
- # @param [Array<Symbol>, nil] id_keys keys to check if index is correct
28
- #
29
- # @return [Relaton::Index::Type] typed index
30
- #
31
- def find_or_create(type, url: nil, file: nil, id_keys: nil)
32
- pool.type(type, url: url, file: file, id_keys: id_keys)
24
+ def find_or_create(type, **args)
25
+ pool.type(type, **args)
33
26
  end
34
27
 
35
28
  def close(type)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-index
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
4
+ version: 0.2.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-03 00:00:00.000000000 Z
11
+ date: 2024-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pubid-core