filerary 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/filerary.gemspec +1 -1
- data/lib/filerary/command.rb +24 -1
- data/lib/filerary/librarian.rb +18 -2
- data/lib/filerary/version.rb +1 -1
- data/test/test-librarian.rb +68 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff8ec69825abc7ab1c238307d3e87aab4f924cd5
|
4
|
+
data.tar.gz: f0df16e83ed22094bd6fdcf6c4ba3d470530c3e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f31e6078cadbdc5f2127666ceef186466d5a286fd7bcd0caedaa8734627ec3c9033d3c354c90bdbeb10a9673c2e76d3c19551d7d29fa990483e10e03fe6653cf
|
7
|
+
data.tar.gz: d77472278b19f8e2cc59410f71472decda58b14136ed155413e07c970bffd8ebd13af5abd969c2e394d42fee96bf7040caa0f87bd4c154809ea41f020c343752
|
data/README.md
CHANGED
@@ -56,17 +56,36 @@ $ filerary list
|
|
56
56
|
$ filerary search WORD
|
57
57
|
```
|
58
58
|
|
59
|
+
### Show a file content
|
60
|
+
|
61
|
+
```bash
|
62
|
+
$ filerary show PATH
|
63
|
+
```
|
64
|
+
|
65
|
+
### Update the collection
|
66
|
+
|
67
|
+
```bash
|
68
|
+
$ filerary update
|
69
|
+
```
|
70
|
+
|
59
71
|
### Remove deleted files in the collection
|
60
72
|
|
61
73
|
```bash
|
62
74
|
$ filerary cleanup
|
63
75
|
```
|
76
|
+
|
64
77
|
### Remove a file in the collection
|
65
78
|
|
66
79
|
```bash
|
67
80
|
$ filerary remove PATH
|
68
81
|
```
|
69
82
|
|
83
|
+
### Delete the database and the collection
|
84
|
+
|
85
|
+
```bash
|
86
|
+
$ filerary destroy
|
87
|
+
```
|
88
|
+
|
70
89
|
## Authors
|
71
90
|
|
72
91
|
* Masafumi Yokoyama `<myokoym@gmail.com>`
|
data/filerary.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.requirements << "LibreOffice"
|
22
22
|
|
23
|
-
spec.add_runtime_dependency("grn_mini")
|
23
|
+
spec.add_runtime_dependency("grn_mini", ">= 0.4.0")
|
24
24
|
spec.add_runtime_dependency("chupa-text")
|
25
25
|
spec.add_runtime_dependency("chupa-text-decomposer-pdf")
|
26
26
|
spec.add_runtime_dependency("chupa-text-decomposer-libreoffice")
|
data/lib/filerary/command.rb
CHANGED
@@ -24,6 +24,20 @@ module Filerary
|
|
24
24
|
puts Filerary::Librarian.new.search(word)
|
25
25
|
end
|
26
26
|
|
27
|
+
desc "show PATH", "Show a file content"
|
28
|
+
def show(path)
|
29
|
+
begin
|
30
|
+
puts Filerary::Librarian.new.show(path)
|
31
|
+
rescue ArgumentError => e
|
32
|
+
STDERR.puts "#{e.class}: #{e.message}: #{path}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "update", "Update the collection"
|
37
|
+
def update
|
38
|
+
Filerary::Librarian.new.update
|
39
|
+
end
|
40
|
+
|
27
41
|
desc "cleanup", "Remove deleted files in the collection"
|
28
42
|
def cleanup
|
29
43
|
Filerary::Librarian.new.cleanup
|
@@ -31,7 +45,16 @@ module Filerary
|
|
31
45
|
|
32
46
|
desc "remove PATH", "Remove a file in the collection"
|
33
47
|
def remove(path)
|
34
|
-
|
48
|
+
begin
|
49
|
+
Filerary::Librarian.new.remove(path)
|
50
|
+
rescue ArgumentError => e
|
51
|
+
STDERR.puts "#{e.class}: #{e.message}: #{path}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
desc "destroy", "Delete the database and the collection"
|
56
|
+
def destroy
|
57
|
+
Filerary::Librarian.new.destroy
|
35
58
|
end
|
36
59
|
end
|
37
60
|
end
|
data/lib/filerary/librarian.rb
CHANGED
@@ -5,7 +5,7 @@ require "chupa-text"
|
|
5
5
|
gem "chupa-text-decomposer-pdf"
|
6
6
|
gem "chupa-text-decomposer-libreoffice"
|
7
7
|
|
8
|
-
# TODO:
|
8
|
+
# TODO: workaround for multibyte filenames for chupa-text gem.
|
9
9
|
module URI
|
10
10
|
class Generic
|
11
11
|
alias :__path__ :path
|
@@ -73,6 +73,16 @@ module Filerary
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
+
def show(path)
|
77
|
+
file = @files[path]
|
78
|
+
raise ArgumentError, "file not found" unless file
|
79
|
+
file.content
|
80
|
+
end
|
81
|
+
|
82
|
+
def update
|
83
|
+
collect(list)
|
84
|
+
end
|
85
|
+
|
76
86
|
def cleanup
|
77
87
|
@files.grn.records.each do |record|
|
78
88
|
path = record._key
|
@@ -81,9 +91,15 @@ module Filerary
|
|
81
91
|
end
|
82
92
|
|
83
93
|
def remove(path)
|
94
|
+
raise ArgumentError, "file not found" unless @files[path]
|
84
95
|
@files.delete(path)
|
85
96
|
end
|
86
97
|
|
98
|
+
def destroy
|
99
|
+
FileUtils.rm(Dir.glob("#{@db_path}*"))
|
100
|
+
FileUtils.rmdir(@db_dir)
|
101
|
+
end
|
102
|
+
|
87
103
|
private
|
88
104
|
def default_base_dir
|
89
105
|
File.join(File.expand_path("~"), ".filerary")
|
@@ -103,7 +119,7 @@ module Filerary
|
|
103
119
|
|
104
120
|
return unless text
|
105
121
|
|
106
|
-
# TODO:
|
122
|
+
# TODO: workaround for multibyte text for chupa-text gem.
|
107
123
|
text.force_encoding(Encoding.default_external)
|
108
124
|
text.force_encoding("UTF-8") unless text.valid_encoding?
|
109
125
|
|
data/lib/filerary/version.rb
CHANGED
data/test/test-librarian.rb
CHANGED
@@ -125,6 +125,49 @@ class FileraryTest < Test::Unit::TestCase
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
+
sub_test_case("show") do
|
129
|
+
def test_found
|
130
|
+
@librarian.collect(__FILE__)
|
131
|
+
assert_equal(File.read(__FILE__), @librarian.show(__FILE__))
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_not_found
|
135
|
+
not_registerd_path = "XXX.txt"
|
136
|
+
@librarian.collect(not_registerd_path)
|
137
|
+
assert_raise(ArgumentError) do
|
138
|
+
@librarian.show(not_registerd_path)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
sub_test_case("update") do
|
144
|
+
def setup
|
145
|
+
super
|
146
|
+
@return_valie_from_collect = "return value from collect"
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_empty
|
150
|
+
files = []
|
151
|
+
@librarian.collect(files)
|
152
|
+
mock(@librarian).collect(files) { @return_valie_from_collect }
|
153
|
+
assert_equal(@return_valie_from_collect, @librarian.update)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_one_file
|
157
|
+
files = [__FILE__]
|
158
|
+
@librarian.collect(files)
|
159
|
+
mock(@librarian).collect(files) { @return_valie_from_collect }
|
160
|
+
assert_equal(@return_valie_from_collect, @librarian.update)
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_multiple_files
|
164
|
+
files = Dir.glob("#{@test_dir}/*.rb").take(2)
|
165
|
+
@librarian.collect(files)
|
166
|
+
mock(@librarian).collect(files) { @return_valie_from_collect }
|
167
|
+
assert_equal(@return_valie_from_collect, @librarian.update)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
128
171
|
sub_test_case("cleanup") do
|
129
172
|
sub_test_case("ascii file name") do
|
130
173
|
def setup
|
@@ -188,5 +231,30 @@ class FileraryTest < Test::Unit::TestCase
|
|
188
231
|
@librarian.remove(__FILE__)
|
189
232
|
assert_equal(0, @librarian.size)
|
190
233
|
end
|
234
|
+
|
235
|
+
def test_not_found
|
236
|
+
not_registerd_path = "XXX.txt"
|
237
|
+
assert_raise(ArgumentError) do
|
238
|
+
@librarian.show(not_registerd_path)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
sub_test_case("destroy") do
|
244
|
+
def setup
|
245
|
+
super
|
246
|
+
@test_tmp_db_dir = File.join(@test_tmp_dir, "db")
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_not_record
|
250
|
+
@librarian.destroy
|
251
|
+
assert_false(File.exist?(@test_tmp_db_dir))
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_have_a_record
|
255
|
+
@librarian.collect(__FILE__)
|
256
|
+
@librarian.destroy
|
257
|
+
assert_false(File.exist?(@test_tmp_db_dir))
|
258
|
+
end
|
191
259
|
end
|
192
260
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filerary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masafumi Yokoyama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grn_mini
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.4.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.4.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: chupa-text
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|