relaton-index 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +3 -3
- data/lib/relaton/index/file_io.rb +27 -10
- data/lib/relaton/index/type.rb +1 -1
- 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: 0eaf31518d3ecfb78041891165d24d8f0e9673d2aebcfa02608694ec9f562843
|
4
|
+
data.tar.gz: 206c0f5fcf0b5336ff186f35da3efc79fda86cf25c93f1c499dd525cccdd6128
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3426d0303d776d0c7ecaeb17bf957a20228858ae859f85aec02d52dc833d643ead02cd14c522d6fcecc72b9f920e2efbc3667f31c86e6dcd363ebc4ef9eae516
|
7
|
+
data.tar.gz: 0e8809f80cc34c92100a081917ce561ccaeb287e9002171f558d62e0c6148ac68a5b4b72f96e8720815f4d3be9390cda026fe39b08c3ba0895706c15a74e8865
|
data/README.adoc
CHANGED
@@ -61,11 +61,11 @@ index.save
|
|
61
61
|
|
62
62
|
=== Searching
|
63
63
|
|
64
|
-
In this case, the Relaton library should create an index object and search for a document by reference. The gem looks for the `.relaton/[TYPE]/index.yaml` file in the user's home directory. The `[TYPE]` is one of downcased ISO, IEC, IHO, etc. If the file is not found or is older than 24 hours then it will be downloaded from the URL specified in the `find_or_create` method.
|
64
|
+
In this case, the Relaton library should create an index object and search for a document by reference. The gem looks for the `.relaton/[TYPE]/index.yaml` file in the user's home directory. The `[TYPE]` is one of downcased ISO, IEC, IHO, etc. If the file is not found or is older than 24 hours then it will be downloaded from the URL specified in the `find_or_create` method. The URL can be specified as `true` if the index should not be fetched from the URL.
|
65
65
|
|
66
66
|
[source,ruby]
|
67
67
|
----
|
68
|
-
# Create a new index object or fetch an existing one. URL should be specified. If the index file is not found or is older than 24 hours, it will be downloaded from the URL. By default, the index is saved as `index.yaml` file to the `/[HOME]/.relaton/iho/` folder.
|
68
|
+
# Create a new index object or fetch an existing one. URL should be specified. If the index file is not found or is older than 24 hours, it will be downloaded from the URL. By default, the index is saved as `index.yaml` file to the `/[HOME]/.relaton/iho/` folder. If the URL is specified as `true`, the index won't be fetched from the URL.
|
69
69
|
index = Relaton::Index.find_or_create :IHO, url: "https://raw.githubusercontent.com/relaton/relaton-data-iho/master/index.zip"
|
70
70
|
|
71
71
|
|
@@ -96,7 +96,7 @@ This method removes the index file. The index object is cleared and can be used
|
|
96
96
|
|
97
97
|
[source,ruby]
|
98
98
|
----
|
99
|
-
index.
|
99
|
+
index.remove_file
|
100
100
|
----
|
101
101
|
|
102
102
|
=== Configuration
|
@@ -12,7 +12,7 @@ module Relaton
|
|
12
12
|
# Initialize FileIO
|
13
13
|
#
|
14
14
|
# @param [String] dir local directory in ~/.relaton to store index
|
15
|
-
# @param [String, nil] url git repository URL to fetch index from
|
15
|
+
# @param [String, Boolean, nil] url git repository URL to fetch index from
|
16
16
|
# (if not exists, or older than 24 hours) or nil if index is used to
|
17
17
|
# index files
|
18
18
|
#
|
@@ -23,27 +23,43 @@ module Relaton
|
|
23
23
|
end
|
24
24
|
|
25
25
|
#
|
26
|
-
#
|
26
|
+
# If url is String, check if index file exists and is not older than 24
|
27
|
+
# hours. If not, fetch index from external repository and save it to
|
28
|
+
# storage.
|
29
|
+
# If url is true, remove index from storage.
|
30
|
+
# If url is nil, read index from file.
|
27
31
|
#
|
28
32
|
# @return [Array<Hash>] index
|
29
33
|
#
|
30
34
|
def read
|
31
|
-
|
32
|
-
|
35
|
+
case url
|
36
|
+
when String
|
33
37
|
check_file || fetch_and_save
|
34
38
|
else
|
35
|
-
@file ||= @filename
|
36
39
|
read_file
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
43
|
+
def file
|
44
|
+
@file ||= url ? path_to_local_file : @filename
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# Create path to local file
|
49
|
+
#
|
50
|
+
# @return [<Type>] <description>
|
51
|
+
#
|
52
|
+
def path_to_local_file
|
53
|
+
File.join(Index.config.storage_dir, ".relaton", @dir, @filename)
|
54
|
+
end
|
55
|
+
|
40
56
|
#
|
41
57
|
# Check if index file exists and is not older than 24 hours
|
42
58
|
#
|
43
59
|
# @return [Array<Hash>, nil] index or nil
|
44
60
|
#
|
45
61
|
def check_file
|
46
|
-
ctime = Index.config.storage.ctime(
|
62
|
+
ctime = Index.config.storage.ctime(file)
|
47
63
|
return unless ctime && ctime > Time.now - 86400
|
48
64
|
|
49
65
|
read_file
|
@@ -55,7 +71,7 @@ module Relaton
|
|
55
71
|
# @return [Array<Hash>] index
|
56
72
|
#
|
57
73
|
def read_file
|
58
|
-
yaml = Index.config.storage.read(
|
74
|
+
yaml = Index.config.storage.read(file)
|
59
75
|
return [] unless yaml
|
60
76
|
|
61
77
|
YAML.safe_load yaml, permitted_classes: [Symbol]
|
@@ -83,16 +99,17 @@ module Relaton
|
|
83
99
|
# @return [void]
|
84
100
|
#
|
85
101
|
def save(index)
|
86
|
-
Index.config.storage.write
|
102
|
+
Index.config.storage.write file, index.to_yaml
|
87
103
|
end
|
88
104
|
|
89
105
|
#
|
90
106
|
# Remove index file from storage
|
91
107
|
#
|
92
|
-
# @return [
|
108
|
+
# @return [Array]
|
93
109
|
#
|
94
110
|
def remove
|
95
|
-
Index.config.storage.remove
|
111
|
+
Index.config.storage.remove file
|
112
|
+
[]
|
96
113
|
end
|
97
114
|
end
|
98
115
|
end
|
data/lib/relaton/index/type.rb
CHANGED
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.
|
4
|
+
version: 0.2.0
|
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-05-
|
11
|
+
date: 2023-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|