findrr 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71340cefdf95336f1b7a90b4952643d0f667d053
4
- data.tar.gz: 7cd17097acf5479006e458785b1f309529da2f64
3
+ metadata.gz: b43b8b92b94614de19cfb1c1285e7c1aeab611fb
4
+ data.tar.gz: 989e319e2cfc2aabbac32c511fe73f58dde0501b
5
5
  SHA512:
6
- metadata.gz: 4a05319bb8169af256455c0fd7873ccfd6668b992675634782de01133d915f54348328dad01afa1dc5a1510c6239e0e5726f1b36f0489aee2d8d4c6d7f18b50e
7
- data.tar.gz: d9afc52c5dc7b5d74dc21463898c16d45d0da6192c7c1109052c6b672ebef0a42496e2e47b60294b28b278663cb5451dc8ec5286655c41333ab4772ef23534ba
6
+ metadata.gz: 7022195f168af37305ef489d0fa8a0ccba04de6bd0dd21f3f8cf52f9758ad3b53b5c6168e7ce3dc124e7a6b1400bc1f853060ab6031e0f81505b7967221d93b4
7
+ data.tar.gz: 1d60e28709ef47dba08d835fb0c9f461aaf05cbecac930f70a8114cb5bf32a4de8038b8bcb34798f5c4a744d80570917bd723733bca3a26c838a75bccdd05ced
data/NEWS.md ADDED
@@ -0,0 +1,16 @@
1
+ # NEWS
2
+
3
+ ## 0.0.2: 2013-12-13
4
+
5
+ Improve the table shcema!
6
+
7
+ ### Changes
8
+
9
+ * Improvements
10
+ * Use PatriciaTrie for type of "Files" table.
11
+ * Added "mtime" column to "Files" table.
12
+ * Added "destroy" command as delete the database.
13
+
14
+ ## 0.0.1: 2013-12-09
15
+
16
+ Initial release!
@@ -5,12 +5,31 @@ module Findrr
5
5
  class Command < Thor
6
6
  desc "collect PATH", "Collect filenames (take a few minutes)"
7
7
  def collect(path)
8
- Database.new.collect(path)
8
+ begin
9
+ Database.new.collect(path)
10
+ rescue => e
11
+ $stderr.puts <<-END_OF_MESSAGE
12
+ Error: #{e.message}
13
+ Hint: table schema might be changed. Please try `findrr destroy` command.
14
+ END_OF_MESSAGE
15
+ end
9
16
  end
10
17
 
11
18
  desc "search PART_OF_FILENAME", "Search for filenames in the collection"
12
19
  def search(part_of_filename)
13
- Database.new.search(part_of_filename)
20
+ begin
21
+ Database.new.search(part_of_filename)
22
+ rescue => e
23
+ $stderr.puts <<-END_OF_MESSAGE
24
+ Error: #{e.message}
25
+ Hint: database probably isn't created. Please try `findrr collect` command.
26
+ END_OF_MESSAGE
27
+ end
28
+ end
29
+
30
+ desc "destroy", "Delete the database and the collection"
31
+ def destroy
32
+ Database.new.destroy
14
33
  end
15
34
  end
16
35
  end
@@ -10,13 +10,15 @@ module Findrr
10
10
  Groonga::Context.default_options = {:encoding => :utf8}
11
11
  end
12
12
 
13
- def collect(path)
13
+ def collect(target)
14
14
  create_database_dir
15
15
  create_database
16
16
  Groonga::Database.open(database_path) do
17
+ Groonga["Registers"].add(target)
17
18
  files = Groonga["Files"]
18
- Find.find(File.expand_path(path)) do |path|
19
- files.add(path, :basename => File.basename(path))
19
+ Find.find(File.expand_path(target)) do |path|
20
+ files.add(path, :basename => File.basename(path),
21
+ :mtime => File.mtime(path))
20
22
  end
21
23
  files.size
22
24
  end
@@ -35,6 +37,10 @@ module Findrr
35
37
  end
36
38
  end
37
39
 
40
+ def destroy
41
+ FileUtils.rm_rf(database_dir)
42
+ end
43
+
38
44
  private
39
45
  def default_base_dir
40
46
  File.join(File.expand_path("~"), ".findrr")
@@ -49,25 +55,27 @@ module Findrr
49
55
  end
50
56
 
51
57
  def create_database_dir
52
- unless File.exist?(database_dir)
53
- FileUtils.mkdir_p(database_dir)
54
- end
58
+ return if File.exist?(database_dir)
59
+ FileUtils.mkdir_p(database_dir)
55
60
  end
56
61
 
57
62
  def create_database
58
- unless File.exist?(database_path)
59
- Groonga::Database.create(:path => database_path)
63
+ return if File.exist?(database_path)
60
64
 
61
- Groonga::Schema.create_table("Files", :type => :hash) do |table|
62
- table.text("basename")
63
- end
65
+ Groonga::Database.create(:path => database_path)
64
66
 
65
- Groonga::Schema.create_table("Terms",
66
- :type => :patricia_trie,
67
- :normalizer => :NormalizerAuto,
68
- :default_tokenizer => "TokenBigram") do |table|
69
- table.index("Files.basename")
70
- end
67
+ Groonga::Schema.create_table("Registers", :type => :hash)
68
+
69
+ Groonga::Schema.create_table("Files", :type => :patricia_trie) do |table|
70
+ table.text("basename")
71
+ table.time("mtime")
72
+ end
73
+
74
+ Groonga::Schema.create_table("Terms",
75
+ :type => :patricia_trie,
76
+ :normalizer => :NormalizerAuto,
77
+ :default_tokenizer => "TokenBigram") do |table|
78
+ table.index("Files.basename")
71
79
  end
72
80
  end
73
81
  end
@@ -1,3 +1,3 @@
1
1
  module Findrr
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -17,4 +17,11 @@ class DatabaseTest < Test::Unit::TestCase
17
17
  assert_true(0 < @database.collect(File.dirname(__FILE__)))
18
18
  assert_true(0 < @database.search("test"))
19
19
  end
20
+
21
+ def test_destroy
22
+ @database.collect(File.dirname(__FILE__))
23
+ assert_true(File.exist?(@tmp_db_dir))
24
+ @database.destroy
25
+ assert_false(File.exist?(@tmp_db_dir))
26
+ end
20
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: findrr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masafumi Yokoyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-09 00:00:00.000000000 Z
11
+ date: 2013-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rroonga
@@ -119,6 +119,7 @@ files:
119
119
  - ".gitignore"
120
120
  - ".travis.yml"
121
121
  - Gemfile
122
+ - NEWS.md
122
123
  - README.md
123
124
  - Rakefile
124
125
  - bin/findrr