relaton-index 0.1.7 → 0.1.8
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 +4 -4
- data/README.adoc +11 -0
- data/lib/relaton/index/file_io.rb +10 -1
- data/lib/relaton/index/file_storage.rb +13 -0
- data/lib/relaton/index/type.rb +17 -4
- data/lib/relaton/index/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60a1a3374a5ce4bf3ed866e1f16c1bfc23e60e540f01689e70f6de64ddd77000
|
4
|
+
data.tar.gz: 2ad750089311e884d7fbe3de14f45769e578a4bd4de76a90ca1710a4733396e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e62a664b3974dcf33b11b04601514aefe89d7891a750d76622097fb66a836fab28808c8f5844e026c5d1578997aa7e8057b2cf34222a5a207f24e2c55ba5f22f
|
7
|
+
data.tar.gz: 4c40187df923f53aa096aa717486f3f82a5cacb0411b1de9886dbbe533f8d7cff6e968aa96c95dc24675a8d192e098839c5ccd67faeaaa2e497570e21b77c464
|
data/README.adoc
CHANGED
@@ -83,11 +83,22 @@ end
|
|
83
83
|
|
84
84
|
=== Remove all index records
|
85
85
|
|
86
|
+
This method removes all records from the index object. The index file is not removed.
|
87
|
+
|
86
88
|
[source,ruby]
|
87
89
|
----
|
88
90
|
index.remove_all
|
89
91
|
----
|
90
92
|
|
93
|
+
=== Remove index file
|
94
|
+
|
95
|
+
This method removes the index file. The index object is cleared and can be used for indexing or loading a file from the specified URL.
|
96
|
+
|
97
|
+
[source,ruby]
|
98
|
+
----
|
99
|
+
index.remove
|
100
|
+
----
|
101
|
+
|
91
102
|
=== Configuration
|
92
103
|
|
93
104
|
The gem can be configured by using the `Relaton::Index.config` method. The following settings are available:
|
@@ -78,13 +78,22 @@ module Relaton
|
|
78
78
|
#
|
79
79
|
# Save index to storage
|
80
80
|
#
|
81
|
-
# @param [Array<Hash>] index
|
81
|
+
# @param [Array<Hash>] index index to save
|
82
82
|
#
|
83
83
|
# @return [void]
|
84
84
|
#
|
85
85
|
def save(index)
|
86
86
|
Index.config.storage.write @file, index.to_yaml
|
87
87
|
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Remove index file from storage
|
91
|
+
#
|
92
|
+
# @return [void]
|
93
|
+
#
|
94
|
+
def remove
|
95
|
+
Index.config.storage.remove @file
|
96
|
+
end
|
88
97
|
end
|
89
98
|
end
|
90
99
|
end
|
@@ -42,6 +42,19 @@ module Relaton
|
|
42
42
|
File.write file, data, encoding: "UTF-8"
|
43
43
|
end
|
44
44
|
|
45
|
+
#
|
46
|
+
# Remove file
|
47
|
+
#
|
48
|
+
# @param [String] file file path
|
49
|
+
#
|
50
|
+
# @return [void]
|
51
|
+
#
|
52
|
+
def remove(file)
|
53
|
+
return unless File.exist? file
|
54
|
+
|
55
|
+
File.delete file
|
56
|
+
end
|
57
|
+
|
45
58
|
extend self
|
46
59
|
end
|
47
60
|
end
|
data/lib/relaton/index/type.rb
CHANGED
@@ -15,7 +15,10 @@ module Relaton
|
|
15
15
|
@file = file
|
16
16
|
filename = file || Index.config.filename
|
17
17
|
@file_io = FileIO.new type.to_s.downcase, url, filename
|
18
|
-
|
18
|
+
end
|
19
|
+
|
20
|
+
def index
|
21
|
+
@index ||= @file_io.read
|
19
22
|
end
|
20
23
|
|
21
24
|
#
|
@@ -41,11 +44,11 @@ module Relaton
|
|
41
44
|
# @return [void]
|
42
45
|
#
|
43
46
|
def add_or_update(id, file)
|
44
|
-
item =
|
47
|
+
item = index.find { |i| i[:id] == id }
|
45
48
|
if item
|
46
49
|
item[:file] = file
|
47
50
|
else
|
48
|
-
|
51
|
+
index << { id: id, file: file }
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
@@ -57,7 +60,7 @@ module Relaton
|
|
57
60
|
# @return [Array<Hash>] search results
|
58
61
|
#
|
59
62
|
def search(id = nil)
|
60
|
-
|
63
|
+
index.select do |i|
|
61
64
|
block_given? ? yield(i) : i[:id].include?(id)
|
62
65
|
end
|
63
66
|
end
|
@@ -71,6 +74,16 @@ module Relaton
|
|
71
74
|
@file_io.save @index
|
72
75
|
end
|
73
76
|
|
77
|
+
#
|
78
|
+
# Remove index file from storage and clear index
|
79
|
+
#
|
80
|
+
# @return [void]
|
81
|
+
#
|
82
|
+
def remove
|
83
|
+
@file_io.remove
|
84
|
+
@index = nil
|
85
|
+
end
|
86
|
+
|
74
87
|
#
|
75
88
|
# Remove all index items
|
76
89
|
#
|