findrr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 71340cefdf95336f1b7a90b4952643d0f667d053
4
+ data.tar.gz: 7cd17097acf5479006e458785b1f309529da2f64
5
+ SHA512:
6
+ metadata.gz: 4a05319bb8169af256455c0fd7873ccfd6668b992675634782de01133d915f54348328dad01afa1dc5a1510c6239e0e5726f1b36f0489aee2d8d4c6d7f18b50e
7
+ data.tar.gz: d9afc52c5dc7b5d74dc21463898c16d45d0da6192c7c1109052c6b672ebef0a42496e2e47b60294b28b278663cb5451dc8ec5286655c41333ab4772ef23534ba
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - ruby-head
6
+ before_install:
7
+ - curl https://raw.github.com/groonga/groonga/master/data/travis/setup.sh | sh
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in findrr.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Findrr [![Build Status](https://secure.travis-ci.org/myokoym/findrr.png?branch=master)](http://travis-ci.org/myokoym/findrr)
2
+
3
+ A search tool for filenames in your directories.
4
+
5
+ ## Requirements
6
+
7
+ * [Rroonga](http://ranguba.org/)
8
+ * [Thor](http://whatisthor.com/)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem "findrr"
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install findrr
23
+
24
+ ## Usage
25
+
26
+ ### Collect filenames (take a few minutes)
27
+
28
+ $ findrr collect PATH
29
+
30
+ ### Search for filenames in the collection
31
+
32
+ $ findrr search PART_OF_FILENAME
33
+
34
+ ## License
35
+
36
+ Copyright (c) 2013 Masafumi Yokoyama
37
+
38
+ LGPLv3 or later.
39
+
40
+ See 'license/lgpl-3.0.txt' or 'http://www.gnu.org/licenses/lgpl-3.0' for details.
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc "Run test"
4
+ task :test do
5
+ Bundler::GemHelper.install_tasks
6
+ ruby("-rubygems", "test/run-test.rb")
7
+ end
8
+
9
+ task :default => :test
data/bin/findrr ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "findrr/command"
4
+
5
+ Findrr::Command.start
data/findrr.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'findrr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "findrr"
8
+ spec.version = Findrr::VERSION
9
+ spec.authors = ["Masafumi Yokoyama"]
10
+ spec.email = ["myokoym@gmail.com"]
11
+ spec.description = %q{A search tool for filenames in your directories.}
12
+ spec.summary = %q{A filenames search tool}
13
+ spec.homepage = "https://github.com/myokoym/findrr"
14
+ spec.license = "LGPLv3 or later"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f)}
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency("rroonga")
22
+ spec.add_runtime_dependency("thor")
23
+
24
+ spec.add_development_dependency("test-unit")
25
+ spec.add_development_dependency("test-unit-notify")
26
+ spec.add_development_dependency("test-unit-rr")
27
+ spec.add_development_dependency("bundler", "~> 1.3")
28
+ spec.add_development_dependency("rake")
29
+ end
@@ -0,0 +1,16 @@
1
+ require "thor"
2
+ require "findrr/database"
3
+
4
+ module Findrr
5
+ class Command < Thor
6
+ desc "collect PATH", "Collect filenames (take a few minutes)"
7
+ def collect(path)
8
+ Database.new.collect(path)
9
+ end
10
+
11
+ desc "search PART_OF_FILENAME", "Search for filenames in the collection"
12
+ def search(part_of_filename)
13
+ Database.new.search(part_of_filename)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,74 @@
1
+ require "fileutils"
2
+ require "find"
3
+ require "groonga"
4
+
5
+ module Findrr
6
+ class Database
7
+ attr_accessor :base_dir
8
+ def initialize(base_dir=default_base_dir)
9
+ @base_dir = base_dir
10
+ Groonga::Context.default_options = {:encoding => :utf8}
11
+ end
12
+
13
+ def collect(path)
14
+ create_database_dir
15
+ create_database
16
+ Groonga::Database.open(database_path) do
17
+ files = Groonga["Files"]
18
+ Find.find(File.expand_path(path)) do |path|
19
+ files.add(path, :basename => File.basename(path))
20
+ end
21
+ files.size
22
+ end
23
+ end
24
+
25
+ def search(part_of_filename)
26
+ Groonga::Database.open(database_path) do
27
+ files = Groonga["Files"]
28
+ found_files = files.select do |record|
29
+ record.basename =~ part_of_filename
30
+ end
31
+ found_files.each do |file|
32
+ puts file._key.force_encoding("locale")
33
+ end
34
+ found_files.size
35
+ end
36
+ end
37
+
38
+ private
39
+ def default_base_dir
40
+ File.join(File.expand_path("~"), ".findrr")
41
+ end
42
+
43
+ def database_dir
44
+ File.join(@base_dir, "db")
45
+ end
46
+
47
+ def database_path
48
+ File.join(database_dir, "findrr.db")
49
+ end
50
+
51
+ def create_database_dir
52
+ unless File.exist?(database_dir)
53
+ FileUtils.mkdir_p(database_dir)
54
+ end
55
+ end
56
+
57
+ def create_database
58
+ unless File.exist?(database_path)
59
+ Groonga::Database.create(:path => database_path)
60
+
61
+ Groonga::Schema.create_table("Files", :type => :hash) do |table|
62
+ table.text("basename")
63
+ end
64
+
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
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module Findrr
2
+ VERSION = "0.0.1"
3
+ end
data/lib/findrr.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "findrr/version"
2
+ require "findrr/database"
3
+
4
+ module Findrr
5
+ end
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/test/run-test.rb ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "test-unit"
4
+ require "test/unit/notify"
5
+ require "test/unit/rr"
6
+
7
+ base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
8
+ $LOAD_PATH.unshift(File.join(base_dir, "test"))
9
+
10
+ exit Test::Unit::AutoRunner.run(true)
@@ -0,0 +1,24 @@
1
+ require "fileutils"
2
+ require "findrr/command"
3
+ require "findrr/database"
4
+
5
+ class CommandTest < Test::Unit::TestCase
6
+ def setup
7
+ @command = Findrr::Command.new
8
+ @database = Findrr::Database.new
9
+ end
10
+
11
+ def test_collect
12
+ path = "foo"
13
+ mock(Findrr::Database).new {@database}
14
+ mock(@database).collect(path)
15
+ @command.collect(path)
16
+ end
17
+
18
+ def test_search
19
+ part_of_filename = "bar"
20
+ mock(Findrr::Database).new {@database}
21
+ mock(@database).search(part_of_filename)
22
+ @command.search(part_of_filename)
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ require "fileutils"
2
+ require "findrr/database"
3
+
4
+ class DatabaseTest < Test::Unit::TestCase
5
+ def setup
6
+ @tmp_dir = File.join(File.dirname(__FILE__), "tmp")
7
+ @tmp_db_dir = File.join(@tmp_dir, "db")
8
+ FileUtils.rm_rf(@tmp_db_dir)
9
+ @database = Findrr::Database.new(@tmp_dir)
10
+ end
11
+
12
+ def teardown
13
+ FileUtils.rm_rf(@tmp_db_dir)
14
+ end
15
+
16
+ def test_collect_and_search
17
+ assert_true(0 < @database.collect(File.dirname(__FILE__)))
18
+ assert_true(0 < @database.search("test"))
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: findrr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Masafumi Yokoyama
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rroonga
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: test-unit-notify
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit-rr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A search tool for filenames in your directories.
112
+ email:
113
+ - myokoym@gmail.com
114
+ executables:
115
+ - findrr
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - bin/findrr
125
+ - findrr.gemspec
126
+ - lib/findrr.rb
127
+ - lib/findrr/command.rb
128
+ - lib/findrr/database.rb
129
+ - lib/findrr/version.rb
130
+ - license/lgpl-3.0.txt
131
+ - test/run-test.rb
132
+ - test/test-command.rb
133
+ - test/test-database.rb
134
+ homepage: https://github.com/myokoym/findrr
135
+ licenses:
136
+ - LGPLv3 or later
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.0
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: A filenames search tool
158
+ test_files:
159
+ - test/run-test.rb
160
+ - test/test-command.rb
161
+ - test/test-database.rb