relaton 0.5.19 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cdab984184fc9dc9f82f55daa2d776167590bd71ec824f358a078c09c15deb0
4
- data.tar.gz: b1348535102098807a0976edb9e621f7765a0fef6a349a2f4a6a113b4232f911
3
+ metadata.gz: 70ae198486401afb2fec19755bf580876116b3b7f9b792c5481c3103c18cc8cc
4
+ data.tar.gz: 6810017f3916e3b1076fe67651aabaccb38020170c365a36d2c21982c8d74e32
5
5
  SHA512:
6
- metadata.gz: 1f92b3be1be13d4cc3a3a7a01021a5d8e21f0db612540286092ddd8c124e231f37b026946f8fbe091a1301ba81265c63b01de0976054d67e7c4be6e1bb83b3af
7
- data.tar.gz: 97c03af34ebdc84fe18dc84fda1d8ce598ad3f609c9e425300eeecf287bb2f0e445e2d5c44c2bc5893585c8ad27394ef6d2f481b5c11b780f61feb7027da69d9
6
+ metadata.gz: 04765c206b5d136190b6fa79f82864f0933859b4f55aa6b196e347cd646d7fb28afa3e958ab54967beee9c6c8b6689bb975fd8c93fbc196b7d08a7c13e3416c6
7
+ data.tar.gz: 7746f838fe703e82517548027b5e5ed0251e091572c83d53a35bd63aead54672d8d0cdc51c7fb00014e34453b3cd8db847c84d70571c86c9d97d4c71d7c01bd5
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton (0.5.19)
5
- relaton-calconnect (~> 0.1.0)
6
- relaton-gb (~> 0.6.0)
7
- relaton-iec (~> 0.4.0)
8
- relaton-ietf (~> 0.6.0)
9
- relaton-iso (~> 0.6.0)
10
- relaton-itu (~> 0.3.0)
11
- relaton-nist (~> 0.3.0)
12
- relaton-ogc (~> 0.1.0)
4
+ relaton (0.6.0)
5
+ relaton-calconnect (~> 0.2.0)
6
+ relaton-gb (~> 0.7.0)
7
+ relaton-iec (~> 0.5.0)
8
+ relaton-ietf (~> 0.7.0)
9
+ relaton-iso (~> 0.7.0)
10
+ relaton-itu (~> 0.4.0)
11
+ relaton-nist (~> 0.4.0)
12
+ relaton-ogc (~> 0.2.0)
13
13
 
14
14
  GEM
15
15
  remote: https://rubygems.org/
@@ -60,7 +60,7 @@ GEM
60
60
  mini_portile2 (2.4.0)
61
61
  multipart-post (2.1.1)
62
62
  nenv (0.3.0)
63
- nokogiri (1.10.5)
63
+ nokogiri (1.10.7)
64
64
  mini_portile2 (~> 2.4.0)
65
65
  notiffany (0.1.1)
66
66
  nenv (~> 0.1)
@@ -81,36 +81,36 @@ GEM
81
81
  rb-fsevent (0.10.3)
82
82
  rb-inotify (0.10.0)
83
83
  ffi (~> 1.0)
84
- relaton-bib (0.3.12)
84
+ relaton-bib (0.4.0)
85
85
  addressable
86
86
  nokogiri
87
- relaton-calconnect (0.1.2)
87
+ relaton-calconnect (0.2.0)
88
88
  faraday
89
- relaton-iso-bib (~> 0.3.0)
90
- relaton-gb (0.6.8)
89
+ relaton-iso-bib (~> 0.4.0)
90
+ relaton-gb (0.7.0)
91
91
  cnccs (~> 0.1.1)
92
92
  gb-agencies (~> 0.0.1)
93
- relaton-iso-bib (~> 0.3.0)
94
- relaton-iec (0.4.12)
93
+ relaton-iso-bib (~> 0.4.0)
94
+ relaton-iec (0.5.0)
95
95
  addressable
96
- relaton-iso-bib (~> 0.3.0)
97
- relaton-ietf (0.6.10)
98
- relaton-bib (~> 0.3.0)
99
- relaton-iso (0.6.10)
100
- relaton-iec (~> 0.4.0)
101
- relaton-iso-bib (~> 0.3.0)
102
- relaton-iso-bib (0.3.12)
96
+ relaton-iso-bib (~> 0.4.0)
97
+ relaton-ietf (0.7.0)
98
+ relaton-bib (~> 0.4.0)
99
+ relaton-iso (0.7.0)
100
+ relaton-iec (~> 0.5.0)
101
+ relaton-iso-bib (~> 0.4.0)
102
+ relaton-iso-bib (0.4.0)
103
103
  isoics (~> 0.1.6)
104
- relaton-bib (~> 0.3.0)
104
+ relaton-bib (~> 0.4.0)
105
105
  ruby_deep_clone (~> 0.8.0)
106
- relaton-itu (0.3.11)
107
- relaton-iso-bib (~> 0.3.0)
108
- relaton-nist (0.3.9)
109
- relaton-bib (~> 0.3.0)
106
+ relaton-itu (0.4.0)
107
+ relaton-iso-bib (~> 0.4.0)
108
+ relaton-nist (0.4.0)
109
+ relaton-bib (~> 0.4.0)
110
110
  rubyzip
111
- relaton-ogc (0.1.4)
111
+ relaton-ogc (0.2.0)
112
112
  faraday
113
- relaton-iso-bib (~> 0.3.0)
113
+ relaton-iso-bib (~> 0.4.0)
114
114
  rspec (3.8.0)
115
115
  rspec-core (~> 3.8.0)
116
116
  rspec-expectations (~> 3.8.0)
data/lib/relaton/db.rb CHANGED
@@ -10,7 +10,6 @@ module Relaton
10
10
  # @param local_cache [String] directory of local DB
11
11
  def initialize(global_cache, local_cache)
12
12
  @registry = Relaton::Registry.instance
13
- # @registry.register_gems
14
13
  @db = open_cache_biblio(global_cache, type: :global)
15
14
  @local_db = open_cache_biblio(local_cache, type: :local)
16
15
  @db_name = global_cache
@@ -144,7 +143,8 @@ module Relaton
144
143
  # @param stdclass [Symbol]
145
144
  # @return [NilClass, RelatonIsoBib::IsoBibliographicItem,
146
145
  # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
147
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
146
+ # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
147
+ # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
148
148
  def check_bibliocache(code, year, opts, stdclass)
149
149
  id, searchcode = std_id(code, year, opts, stdclass)
150
150
  yaml = @static_db[id]
@@ -209,16 +209,21 @@ module Relaton
209
209
  return nil if dir.nil?
210
210
 
211
211
  db = DbCache.new dir, type == :static ? "yml" : "xml"
212
- return db if db.check_version?
213
-
214
- case type
215
- when :global
216
- FileUtils.rm_rf(Dir.glob(dir + "/*"), secure: true)
217
- warn "Global cache version is obsolete and cleared."
218
- db.set_version
219
- when :static then warn "Static cache version is obsolete."
220
- else warn "Local cache version is obsolete."
212
+ # return db if db.check_version?
213
+
214
+ Dir["#{dir}/*/"].each do |fdir|
215
+ next if type == :static || db.check_version?(fdir)
216
+
217
+ # case type
218
+ # when :global
219
+ # else
220
+ FileUtils.rm_rf(Dir.glob(fdir + "/*"), secure: true)
221
+ warn "Cache #{fdir}: version is obsolete and cahe is cleared."
222
+ # db.set_version fdir
223
+ # else warn "Local cache #{fdir}: version is obsolete."
224
+ # end
221
225
  end
226
+ db
222
227
  end
223
228
  end
224
229
  end
@@ -10,8 +10,8 @@ module Relaton
10
10
  @dir = dir
11
11
  @ext = ext
12
12
  FileUtils::mkdir_p @dir
13
- file_version = "#{@dir}/version"
14
- set_version unless File.exist? file_version
13
+ # file_version = "#{@dir}/version"
14
+ # set_version # unless File.exist? file_version
15
15
  end
16
16
 
17
17
  # Save item
@@ -24,7 +24,10 @@ module Relaton
24
24
  end
25
25
 
26
26
  prefix_dir = "#{@dir}/#{prefix(key)}"
27
- FileUtils::mkdir_p prefix_dir
27
+ unless Dir.exist? prefix_dir
28
+ FileUtils::mkdir_p prefix_dir
29
+ set_version prefix_dir
30
+ end
28
31
  File.write filename(key), value, encoding: "utf-8"
29
32
  end
30
33
 
@@ -63,7 +66,7 @@ module Relaton
63
66
  end
64
67
 
65
68
  # Returns all items
66
- # @return [Array<Hash>]
69
+ # @return [Array<String>]
67
70
  def all
68
71
  Dir.glob("#{@dir}/**/*.xml").sort.map do |f|
69
72
  File.read(f, encoding: "utf-8")
@@ -77,17 +80,25 @@ module Relaton
77
80
  File.delete file if File.exist? file
78
81
  end
79
82
 
80
- # Check if version of the DB match to the gem version.
83
+ # Check if version of the DB match to the gem grammar hash.
84
+ # @param fdir [String] dir pathe to flover cache
81
85
  # @return [TrueClass, FalseClass]
82
- def check_version?
83
- v = File.read @dir + "/version", encoding: "utf-8"
84
- v.strip == VERSION
86
+ def check_version?(fdir)
87
+ version_dir = fdir + "/version"
88
+ return false unless File.exist? version_dir
89
+
90
+ v = File.read version_dir, encoding: "utf-8"
91
+ v.strip == grammar_hash(fdir)
85
92
  end
86
93
 
87
- # Set version of the DB to the gem version.
94
+ # Set version of the DB to the gem grammar hash.
95
+ # @param fdir [String] dir pathe to flover cache
88
96
  # @return [Relaton::DbCache]
89
- def set_version
90
- File.write @dir + "/version", VERSION, encoding: "utf-8"
97
+ def set_version(fdir)
98
+ file_version = "#{fdir}/version"
99
+ unless File.exist? file_version
100
+ File.write file_version, grammar_hash(fdir), encoding: "utf-8"
101
+ end
91
102
  self
92
103
  end
93
104
 
@@ -104,6 +115,13 @@ module Relaton
104
115
 
105
116
  protected
106
117
 
118
+ # @param fdir [String] dir pathe to flover cache
119
+ # @return [String]
120
+ def grammar_hash(fdir)
121
+ type = fdir.split("/").last
122
+ Relaton::Registry.instance.by_type(type).grammar_hash
123
+ end
124
+
107
125
  # Reads file by a key
108
126
  #
109
127
  # @param key [String]
@@ -55,9 +55,11 @@ module Relaton
55
55
  # Find processor by type
56
56
  #
57
57
  # @param type [String]
58
- # @return [Relaton::RelatonIso::Processor]
58
+ # @return [RelatonIso::Processor, RelatonIec::Processor, RelatonNist::Processor,
59
+ # RelatonIetf::Processot, RelatonItu::Processor, RelatonGb::Processor,
60
+ # RelatonOgc::Processor, RelatonCalconnect::Processor]
59
61
  def by_type(type)
60
- processors.values.detect { |v| v.idtype == type.upcase }
62
+ processors.values.detect { |v| v.prefix == type.upcase }
61
63
  end
62
64
 
63
65
  private
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "0.5.19".freeze
2
+ VERSION = "0.6.0".freeze
3
3
  end
data/relaton.gemspec CHANGED
@@ -29,14 +29,14 @@ model.
29
29
  spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
30
30
 
31
31
  # spec.add_dependency "algoliasearch"
32
- spec.add_dependency "relaton-calconnect", "~> 0.1.0"
33
- spec.add_dependency "relaton-gb", "~> 0.6.0"
34
- spec.add_dependency "relaton-iec", "~> 0.4.0"
35
- spec.add_dependency "relaton-ietf", "~> 0.6.0"
36
- spec.add_dependency "relaton-iso", "~> 0.6.0"
37
- spec.add_dependency "relaton-itu", "~> 0.3.0"
38
- spec.add_dependency "relaton-nist", "~> 0.3.0"
39
- spec.add_dependency "relaton-ogc", "~> 0.1.0"
32
+ spec.add_dependency "relaton-calconnect", "~> 0.2.0"
33
+ spec.add_dependency "relaton-gb", "~> 0.7.0"
34
+ spec.add_dependency "relaton-iec", "~> 0.5.0"
35
+ spec.add_dependency "relaton-ietf", "~> 0.7.0"
36
+ spec.add_dependency "relaton-iso", "~> 0.7.0"
37
+ spec.add_dependency "relaton-itu", "~> 0.4.0"
38
+ spec.add_dependency "relaton-nist", "~> 0.4.0"
39
+ spec.add_dependency "relaton-ogc", "~> 0.2.0"
40
40
 
41
41
  spec.add_development_dependency "bundler", "~> 2.0.1"
42
42
  spec.add_development_dependency "byebug", "~> 10.0"
@@ -1,11 +1,11 @@
1
1
  RSpec.describe Relaton::DbCache do
2
2
  it "creates default caches" do
3
- FileUtils.mv File.expand_path("~/.relaton"), "relaton1", force: true
3
+ FileUtils.mv File.expand_path("~/.relaton/cache"), "relaton1/cache", force: true
4
4
  FileUtils.rm_rf %w(relaton)
5
5
  Relaton::DbCache.init_bib_caches(global_cache: true, local_cache: "", flush_caches: true)
6
- expect(File.exist?(File.expand_path("~/.relaton"))).to be true
6
+ expect(File.exist?(File.expand_path("~/.relaton/cache"))).to be true
7
7
  expect(File.exist?("relaton")).to be true
8
- FileUtils.mv "relaton1", File.expand_path("~/.relaton") if File.exist? "relaton1"
8
+ FileUtils.mv "relaton1/cache", File.expand_path("~/.relaton/cache") if File.exist? "relaton1"
9
9
  end
10
10
 
11
11
  # it "returns fetched" do
data/spec/relaton_spec.rb CHANGED
@@ -173,14 +173,17 @@ RSpec.describe Relaton::Db do
173
173
  end
174
174
 
175
175
  it "should clear global cache if version is changed" do
176
- @db.save_entry "test_key", value: "test_value"
176
+ @db.save_entry "iso(test_key)", value: "test_value"
177
177
  expect(File.exist?("testcache")).to be true
178
178
  expect(File.exist?("testcache2")).to be true
179
- stub_const "Relaton::VERSION", "new_version"
179
+ # stub_const "Relaton::VERSION", "new_version"
180
+ processor = double
181
+ expect(processor).to receive(:grammar_hash).and_return("new_version").exactly(2).times
182
+ expect(Relaton::Registry.instance).to receive(:by_type).and_return(processor).exactly(2).times
180
183
  db = Relaton::Db.new "testcache", "testcache2"
181
184
  testcache = db.instance_variable_get :@db
182
- expect(testcache.all.any?).to be false
185
+ expect(testcache.all).not_to be_any
183
186
  testcache = db.instance_variable_get :@local_db
184
- expect(testcache).to be_nil
187
+ expect(testcache.all).not_to be_any
185
188
  end
186
189
  end