relaton-index 0.1.9 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +2 -2
- data/lib/relaton/index/file_io.rb +19 -17
- data/lib/relaton/index/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39ea35c85bb825679fc73792345d3c11217e80972f2eb32c1a4cc5b31b1a41de
|
4
|
+
data.tar.gz: eedc5afbe9b1fcbd76763d26b628b510e29a9f0a9c74d1a2bb4ab554b0ffb0f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e420ccb8c3d7eaa8834d02c901b0ff495ec6f16552fb614b81905d15758228553eb399234b2575a6bf905931dc96c11491f90082355c28f5be8ba3fa2a0edb44
|
7
|
+
data.tar.gz: 63971b59580a47e70782a0e6a1b98acb270953b415ed451f2b634a5baebafbc46ea7ca08b83a5a76f5110e95d96af27ba64ab8a63fbc6feb850118553b4b6611
|
data/README.adoc
CHANGED
@@ -33,7 +33,7 @@ Relaton::Index.find_or_create :IHO, url: "https://raw.githubusercontent.com/rela
|
|
33
33
|
Relaton::Index.find_or_create :IHO
|
34
34
|
|
35
35
|
# If the URL or filename is specified and has a new value (different from what it was before), the index object will be recreated.
|
36
|
-
Relaton::Index.find_or_create :IHO, url: nil,
|
36
|
+
Relaton::Index.find_or_create :IHO, url: nil, file: "index.yaml"
|
37
37
|
|
38
38
|
# Remove the index from the pool.
|
39
39
|
Relaton::Index.close :IHO
|
@@ -53,7 +53,7 @@ In this case, the Relaton library creates an index object and adds documents' fi
|
|
53
53
|
index = Relaton::Index.find_or_create :IHO
|
54
54
|
|
55
55
|
# Add a document to the index or update it if it already exists.
|
56
|
-
index.add_or_update
|
56
|
+
index.add_or_update "B-4 2.19.0", "data/b-4_2_19_0.xml"
|
57
57
|
|
58
58
|
# Save the index to the `index.yaml` file in the current directory.
|
59
59
|
index.save
|
@@ -11,10 +11,12 @@ module Relaton
|
|
11
11
|
#
|
12
12
|
# Initialize FileIO
|
13
13
|
#
|
14
|
-
# @param [String] dir local directory in ~/.relaton to store index
|
15
|
-
# @param [String, Boolean, nil] url
|
16
|
-
#
|
17
|
-
#
|
14
|
+
# @param [String] dir falvor specific local directory in ~/.relaton to store index
|
15
|
+
# @param [String, Boolean, nil] url
|
16
|
+
# if String then the URL is used to fetch an index from a Git repository
|
17
|
+
# and save it to the storage (if not exists, or older than 24 hours)
|
18
|
+
# if true then the index is read from the storage (used to remove index file)
|
19
|
+
# if nil then the fiename is used to read and write file (used to create indes in GH actions)
|
18
20
|
#
|
19
21
|
def initialize(dir, url, filename)
|
20
22
|
@dir = dir
|
@@ -26,25 +28,24 @@ module Relaton
|
|
26
28
|
# If url is String, check if index file exists and is not older than 24
|
27
29
|
# hours. If not, fetch index from external repository and save it to
|
28
30
|
# storage.
|
29
|
-
# If url is true,
|
30
|
-
# If url is nil, read index from
|
31
|
+
# If url is true, read index from path to local file.
|
32
|
+
# If url is nil, read index from filename.
|
31
33
|
#
|
32
34
|
# @return [Array<Hash>] index
|
33
35
|
#
|
34
36
|
def read
|
35
37
|
case url
|
36
38
|
when String
|
37
|
-
@file ||= path_to_local_file
|
38
39
|
check_file || fetch_and_save
|
39
|
-
when true
|
40
|
-
@file ||= path_to_local_file
|
41
|
-
read_file
|
42
40
|
else
|
43
|
-
|
44
|
-
read_file
|
41
|
+
read_file || []
|
45
42
|
end
|
46
43
|
end
|
47
44
|
|
45
|
+
def file
|
46
|
+
@file ||= url ? path_to_local_file : @filename
|
47
|
+
end
|
48
|
+
|
48
49
|
#
|
49
50
|
# Create path to local file
|
50
51
|
#
|
@@ -60,7 +61,7 @@ module Relaton
|
|
60
61
|
# @return [Array<Hash>, nil] index or nil
|
61
62
|
#
|
62
63
|
def check_file
|
63
|
-
ctime = Index.config.storage.ctime(
|
64
|
+
ctime = Index.config.storage.ctime(file)
|
64
65
|
return unless ctime && ctime > Time.now - 86400
|
65
66
|
|
66
67
|
read_file
|
@@ -72,10 +73,11 @@ module Relaton
|
|
72
73
|
# @return [Array<Hash>] index
|
73
74
|
#
|
74
75
|
def read_file
|
75
|
-
yaml = Index.config.storage.read(
|
76
|
-
return
|
76
|
+
yaml = Index.config.storage.read(file)
|
77
|
+
return unless yaml
|
77
78
|
|
78
79
|
YAML.safe_load yaml, permitted_classes: [Symbol]
|
80
|
+
rescue Psych::SyntaxError
|
79
81
|
end
|
80
82
|
|
81
83
|
#
|
@@ -100,7 +102,7 @@ module Relaton
|
|
100
102
|
# @return [void]
|
101
103
|
#
|
102
104
|
def save(index)
|
103
|
-
Index.config.storage.write
|
105
|
+
Index.config.storage.write file, index.to_yaml
|
104
106
|
end
|
105
107
|
|
106
108
|
#
|
@@ -109,7 +111,7 @@ module Relaton
|
|
109
111
|
# @return [Array]
|
110
112
|
#
|
111
113
|
def remove
|
112
|
-
Index.config.storage.remove
|
114
|
+
Index.config.storage.remove file
|
113
115
|
[]
|
114
116
|
end
|
115
117
|
end
|
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.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|