filerary 0.0.5 → 0.0.6
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/.travis.yml +4 -0
- data/README.md +11 -0
- data/filerary.gemspec +0 -4
- data/lib/filerary/command.rb +10 -0
- data/lib/filerary/librarian.rb +19 -2
- data/lib/filerary/version.rb +1 -1
- data/test/test-librarian.rb +94 -27
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7ddc8adb48ea4b83698e623511cdc5726cc0f05
|
4
|
+
data.tar.gz: 1aa65fc9463f42ad20da85150ca4f89355d2584f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 224cd1a37fcfc3f82340767c905b5f9bcc0edb0422e467e38b74a47bbad5ba54397f1c19596adc323497db0fced0e33e9075182d7a2064d3b98896efb30f7698
|
7
|
+
data.tar.gz: 5316ec5a05c9bf8e78374e11e89635c2d2cb007e34b27c8f9d744c7314facf9c7f478f871aa90ce21bf2ea9994364a079069b93c8339ca609473d52bb77b92a2
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -44,6 +44,12 @@ $ gem install filerary
|
|
44
44
|
$ filerary collect FILE...
|
45
45
|
```
|
46
46
|
|
47
|
+
### List filenames in the collection
|
48
|
+
|
49
|
+
```bash
|
50
|
+
$ filerary list
|
51
|
+
```
|
52
|
+
|
47
53
|
### Search for files in the collection (very fast!)
|
48
54
|
|
49
55
|
```bash
|
@@ -55,6 +61,11 @@ $ filerary search WORD
|
|
55
61
|
```bash
|
56
62
|
$ filerary cleanup
|
57
63
|
```
|
64
|
+
### Remove a file in the collection
|
65
|
+
|
66
|
+
```bash
|
67
|
+
$ filerary remove PATH
|
68
|
+
```
|
58
69
|
|
59
70
|
## Authors
|
60
71
|
|
data/filerary.gemspec
CHANGED
@@ -13,10 +13,6 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/myokoym/filerary"
|
14
14
|
spec.license = "LGPLv2.1 or later"
|
15
15
|
|
16
|
-
spec.post_install_message = <<-END_OF_MESSAGE
|
17
|
-
Filerary will use '#{File.join(File.expand_path("~"), ".filerary")}' for data storage. Thanks!
|
18
|
-
END_OF_MESSAGE
|
19
|
-
|
20
16
|
spec.files = `git ls-files -z`.split("\x0")
|
21
17
|
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
22
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
data/lib/filerary/command.rb
CHANGED
@@ -9,6 +9,11 @@ module Filerary
|
|
9
9
|
puts VERSION
|
10
10
|
end
|
11
11
|
|
12
|
+
desc "list", "List filenames in the collection"
|
13
|
+
def list
|
14
|
+
puts Filerary::Librarian.new.list
|
15
|
+
end
|
16
|
+
|
12
17
|
desc "collect FILE...", "Collect files (takes time)"
|
13
18
|
def collect(*files)
|
14
19
|
Filerary::Librarian.new.collect(files)
|
@@ -23,5 +28,10 @@ module Filerary
|
|
23
28
|
def cleanup
|
24
29
|
Filerary::Librarian.new.cleanup
|
25
30
|
end
|
31
|
+
|
32
|
+
desc "remove PATH", "Remove a file in the collection"
|
33
|
+
def remove(path)
|
34
|
+
Filerary::Librarian.new.remove(path)
|
35
|
+
end
|
26
36
|
end
|
27
37
|
end
|
data/lib/filerary/librarian.rb
CHANGED
@@ -33,6 +33,16 @@ module Filerary
|
|
33
33
|
@files = GrnMini::Hash.new("Files")
|
34
34
|
end
|
35
35
|
|
36
|
+
def size
|
37
|
+
@files.size
|
38
|
+
end
|
39
|
+
|
40
|
+
def list
|
41
|
+
@files.collect do |record|
|
42
|
+
record._key
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
36
46
|
def collect(paths)
|
37
47
|
paths = [paths] if paths.is_a?(String)
|
38
48
|
|
@@ -43,8 +53,11 @@ module Filerary
|
|
43
53
|
next if /\/\.git\// =~ path
|
44
54
|
next if @files[path] && @files[path].updated_at > File.mtime(path)
|
45
55
|
|
56
|
+
content = read_content(path)
|
57
|
+
next unless content
|
58
|
+
|
46
59
|
@files[path] = {
|
47
|
-
:content =>
|
60
|
+
:content => content,
|
48
61
|
:updated_at => Time.now,
|
49
62
|
}
|
50
63
|
end
|
@@ -67,6 +80,10 @@ module Filerary
|
|
67
80
|
end
|
68
81
|
end
|
69
82
|
|
83
|
+
def remove(path)
|
84
|
+
@files.delete(path)
|
85
|
+
end
|
86
|
+
|
70
87
|
private
|
71
88
|
def default_base_dir
|
72
89
|
File.join(File.expand_path("~"), ".filerary")
|
@@ -84,7 +101,7 @@ module Filerary
|
|
84
101
|
text = text_data.body
|
85
102
|
end
|
86
103
|
|
87
|
-
return
|
104
|
+
return unless text
|
88
105
|
|
89
106
|
# TODO: I want to specify encoding in ChupaText side.
|
90
107
|
text.force_encoding(Encoding.default_external)
|
data/lib/filerary/version.rb
CHANGED
data/test/test-librarian.rb
CHANGED
@@ -26,8 +26,25 @@ class FileraryTest < Test::Unit::TestCase
|
|
26
26
|
assert_equal(default_db_dir, librarian.db_dir)
|
27
27
|
end
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
sub_test_case("list") do
|
30
|
+
def test_empty
|
31
|
+
assert_equal([], @librarian.list)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_one_file
|
35
|
+
@librarian.collect(__FILE__)
|
36
|
+
assert_equal([__FILE__], @librarian.list)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_multiple_files
|
40
|
+
files = Dir.glob("#{@test_dir}/*.rb").take(2)
|
41
|
+
@librarian.collect(files)
|
42
|
+
assert_equal(files, @librarian.list)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
sub_test_case("collect") do
|
47
|
+
sub_test_case("argument") do
|
31
48
|
def test_string
|
32
49
|
assert_equal([__FILE__], @librarian.collect(__FILE__))
|
33
50
|
end
|
@@ -37,30 +54,42 @@ class FileraryTest < Test::Unit::TestCase
|
|
37
54
|
end
|
38
55
|
end
|
39
56
|
|
40
|
-
|
57
|
+
sub_test_case("file path") do
|
41
58
|
def test_multibyte
|
42
59
|
Dir.mktmpdir do |tmpdir|
|
43
60
|
path = File.join(tmpdir, "マルチバイト.txt")
|
44
61
|
FileUtils.touch(path)
|
45
|
-
|
62
|
+
@librarian.collect(path)
|
63
|
+
assert_equal(1, @librarian.size)
|
46
64
|
end
|
47
65
|
end
|
48
66
|
end
|
49
67
|
|
50
|
-
|
68
|
+
sub_test_case("file type") do
|
51
69
|
def test_pdf
|
52
70
|
path = File.join(@test_fixtures_dir, "test-pdf.pdf")
|
53
|
-
|
71
|
+
@librarian.collect(path)
|
72
|
+
assert_equal(1, @librarian.size)
|
54
73
|
end
|
55
74
|
|
56
75
|
def test_xls
|
57
76
|
path = File.join(@test_fixtures_dir, "test-excel.xls")
|
58
|
-
|
77
|
+
@librarian.collect(path)
|
78
|
+
assert_equal(1, @librarian.size)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
sub_test_case("file content") do
|
83
|
+
def test_empty
|
84
|
+
path = "empty"
|
85
|
+
stub(@librarian).read_content(path) { nil }
|
86
|
+
@librarian.collect(path)
|
87
|
+
assert_equal(0, @librarian.size)
|
59
88
|
end
|
60
89
|
end
|
61
90
|
end
|
62
91
|
|
63
|
-
|
92
|
+
sub_test_case("search") do
|
64
93
|
def test_found
|
65
94
|
@librarian.collect(__FILE__)
|
66
95
|
assert_equal([__FILE__], @librarian.search("Librarian"))
|
@@ -96,30 +125,68 @@ class FileraryTest < Test::Unit::TestCase
|
|
96
125
|
end
|
97
126
|
end
|
98
127
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
128
|
+
sub_test_case("cleanup") do
|
129
|
+
sub_test_case("ascii file name") do
|
130
|
+
def setup
|
131
|
+
super
|
132
|
+
@temp_file = File.join(@test_tmp_dir, "cleanup.txt")
|
133
|
+
FileUtils.cp(__FILE__, @temp_file)
|
134
|
+
@librarian.collect(@temp_file)
|
135
|
+
end
|
136
|
+
|
137
|
+
def teardown
|
138
|
+
super
|
139
|
+
FileUtils.rm_f(@temp_file)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_removed
|
143
|
+
FileUtils.rm(@temp_file)
|
144
|
+
assert_equal([@temp_file], @librarian.search("Librarian"))
|
145
|
+
@librarian.cleanup
|
146
|
+
assert_equal([], @librarian.search("Librarian"))
|
147
|
+
end
|
106
148
|
|
107
|
-
|
108
|
-
|
109
|
-
|
149
|
+
def test_not_removed
|
150
|
+
assert_equal([@temp_file], @librarian.search("Librarian"))
|
151
|
+
@librarian.cleanup
|
152
|
+
assert_equal([@temp_file], @librarian.search("Librarian"))
|
153
|
+
end
|
110
154
|
end
|
111
155
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
156
|
+
sub_test_case("multibyte file name") do
|
157
|
+
def setup
|
158
|
+
super
|
159
|
+
@temp_file = File.join(@test_tmp_dir, "マルチバイト.txt")
|
160
|
+
FileUtils.cp(__FILE__, @temp_file)
|
161
|
+
@librarian.collect(@temp_file)
|
162
|
+
end
|
163
|
+
|
164
|
+
def teardown
|
165
|
+
super
|
166
|
+
FileUtils.rm_f(@temp_file)
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_removed
|
170
|
+
FileUtils.rm(@temp_file)
|
171
|
+
assert_equal([@temp_file], @librarian.search("Librarian"))
|
172
|
+
@librarian.cleanup
|
173
|
+
assert_equal([], @librarian.search("Librarian"))
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_not_removed
|
177
|
+
assert_equal([@temp_file], @librarian.search("Librarian"))
|
178
|
+
@librarian.cleanup
|
179
|
+
assert_equal([@temp_file], @librarian.search("Librarian"))
|
180
|
+
end
|
117
181
|
end
|
182
|
+
end
|
118
183
|
|
119
|
-
|
120
|
-
|
121
|
-
@librarian.
|
122
|
-
assert_equal(
|
184
|
+
sub_test_case("remove") do
|
185
|
+
def test_one_file
|
186
|
+
@librarian.collect(__FILE__)
|
187
|
+
assert_equal(1, @librarian.size)
|
188
|
+
@librarian.remove(__FILE__)
|
189
|
+
assert_equal(0, @librarian.size)
|
123
190
|
end
|
124
191
|
end
|
125
192
|
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.6
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grn_mini
|
@@ -180,8 +180,7 @@ homepage: https://github.com/myokoym/filerary
|
|
180
180
|
licenses:
|
181
181
|
- LGPLv2.1 or later
|
182
182
|
metadata: {}
|
183
|
-
post_install_message:
|
184
|
-
Filerary will use '/home/myokoym/.filerary' for data storage. Thanks!
|
183
|
+
post_install_message:
|
185
184
|
rdoc_options: []
|
186
185
|
require_paths:
|
187
186
|
- lib
|