peaches 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "yard", "~> 0.7.5"
11
+ gem "guard-rspec"
12
+ gem "pry"
13
+ gem "pry-doc"
14
+ gem "pry_debug"
15
+ gem "guard-spork"
16
+ gem "bundler", "~> 1.0.21"
17
+ gem "jeweler", "~> 1.5.2"
18
+ gem "simplecov", ">= 0"
19
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,62 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ coderay (1.0.5)
5
+ diff-lcs (1.1.3)
6
+ ffi (1.0.11)
7
+ git (1.2.5)
8
+ guard (1.0.0)
9
+ ffi (>= 0.5.0)
10
+ thor (~> 0.14.6)
11
+ guard-rspec (0.6.0)
12
+ guard (>= 0.10.0)
13
+ guard-spork (0.5.2)
14
+ guard (>= 0.10.0)
15
+ spork (>= 0.8.4)
16
+ jeweler (1.5.2)
17
+ bundler (~> 1.0.0)
18
+ git (>= 1.2.5)
19
+ rake
20
+ method_source (0.7.0)
21
+ multi_json (1.0.4)
22
+ pry (0.9.8.1)
23
+ coderay (~> 1.0.5)
24
+ method_source (~> 0.7)
25
+ slop (>= 2.4.3, < 3)
26
+ pry-doc (0.4.0)
27
+ pry (>= 0.9.0)
28
+ yard (~> 0.7.4)
29
+ pry_debug (0.0.1)
30
+ pry (~> 0.9.0)
31
+ rake (0.9.2.2)
32
+ rspec (2.8.0)
33
+ rspec-core (~> 2.8.0)
34
+ rspec-expectations (~> 2.8.0)
35
+ rspec-mocks (~> 2.8.0)
36
+ rspec-core (2.8.0)
37
+ rspec-expectations (2.8.0)
38
+ diff-lcs (~> 1.1.2)
39
+ rspec-mocks (2.8.0)
40
+ simplecov (0.5.4)
41
+ multi_json (~> 1.0.3)
42
+ simplecov-html (~> 0.5.3)
43
+ simplecov-html (0.5.3)
44
+ slop (2.4.3)
45
+ spork (0.9.0)
46
+ thor (0.14.6)
47
+ yard (0.7.5)
48
+
49
+ PLATFORMS
50
+ ruby
51
+
52
+ DEPENDENCIES
53
+ bundler (~> 1.0.21)
54
+ guard-rspec
55
+ guard-spork
56
+ jeweler (~> 1.5.2)
57
+ pry
58
+ pry-doc
59
+ pry_debug
60
+ rspec (~> 2.8.0)
61
+ simplecov
62
+ yard (~> 0.7.5)
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ #guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
5
+ #watch('config/application.rb')
6
+ #watch('config/environment.rb')
7
+ #watch(%r{^config/environments/.+\.rb$})
8
+ #watch(%r{^config/initializers/.+\.rb$})
9
+ #watch('Gemfile')
10
+ #watch('Gemfile.lock')
11
+ #watch('spec/spec_helper.rb') { :rspec }
12
+ #watch('test/test_helper.rb') { :test_unit }
13
+ #watch(%r{features/support/}) { :cucumber }
14
+ #end
15
+
16
+ guard 'rspec', :cli => "--drb --color --format nested", :version => 2 do
17
+ watch(%r{^spec/.+_spec\.rb$})
18
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
19
+ watch('spec/spec_helper.rb') { "spec" }
20
+ end
21
+
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Brady Love
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # peaches
2
+
3
+ A simple fuzzy file finder built on Ruby. This is mainly just for learning purpose, may release one day once I perfect it.
4
+
5
+ <!--== Contributing to peaches-->
6
+
7
+ <!--* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet-->
8
+ <!--* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it-->
9
+ <!--* Fork the project-->
10
+ <!--* Start a feature/bugfix branch-->
11
+ <!--* Commit and push until you are happy with your contribution-->
12
+ <!--* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.-->
13
+ <!--* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.-->
14
+
15
+ ## Copyright
16
+
17
+ Copyright (c) 2012 Brady Love. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "peaches"
16
+ gem.homepage = "http://github.com/bradylove/peaches"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{A simple fuzzy file finder written in Ruby}
19
+ gem.description = %Q{write a description}
20
+ gem.email = "love.brady@gmail.com"
21
+ gem.authors = ["Brady Love"]
22
+ gem.executables = ['peaches']
23
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
24
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
25
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
26
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rspec/core'
31
+ require 'rspec/core/rake_task'
32
+ RSpec::Core::RakeTask.new(:spec) do |spec|
33
+ spec.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
37
+ spec.pattern = 'spec/**/*_spec.rb'
38
+ spec.rcov = true
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'yard'
44
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/bin/peaches ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'peaches'
4
+
5
+ # Returns files found fuzzily from string
6
+ # Usage:
7
+ # peaches "search string"
8
+ # or
9
+ # peaches
10
+ finder = Peaches::Finder.new(Dir.pwd)
11
+
12
+ if ARGV.empty?
13
+ while true do
14
+ puts "Enter Search String: "
15
+ string = gets.chomp
16
+ puts ""
17
+ puts "Results"
18
+ puts "-------------------------"
19
+
20
+ results = finder.find(string)
21
+ puts results
22
+ puts ""
23
+ end
24
+ else
25
+ puts finder.find(ARGV[0])
26
+ end
27
+
28
+
29
+
@@ -0,0 +1,59 @@
1
+ module Peaches
2
+ class Finder
3
+ attr_accessor :cache
4
+
5
+ # Init
6
+ #
7
+ # == Parameters
8
+ # root::
9
+ # The root directory to cache
10
+ def initialize(root)
11
+ @root = root
12
+ end
13
+
14
+ # FuzzyFind files from the cache
15
+ #
16
+ # == Paarameters
17
+ # string::
18
+ # The string you want to use to find matching files, if left black it
19
+ # will bring up all the files
20
+ def find(string)
21
+ string = string.split(//).join(".*?")
22
+ pattern = "/#{string}/i"
23
+
24
+ results = self.cache.grep /#{string}/i
25
+
26
+ return results
27
+ end
28
+
29
+ # forces a refresh of the file list cache
30
+ def refresh_cache
31
+ @cache = build_cache
32
+ end
33
+
34
+ # Get and/or fetch the file list cache
35
+ def cache
36
+ @cache ||= build_cache
37
+ end
38
+
39
+ # Builds the cache excluding files that start with .
40
+ def build_cache
41
+ all_files = []
42
+
43
+ Find.find(@root) do |path|
44
+ if FileTest.directory?(path)
45
+ if File.basename(path)[0] == ?.
46
+ Find.prune
47
+ else
48
+ next
49
+ end
50
+ else
51
+ path.slice!("#{@root}/")
52
+ all_files << path
53
+ end
54
+ end
55
+
56
+ return all_files
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module Peaches
2
+ VERSION = '0.0.1'
3
+ end
data/lib/peaches.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'peaches/version'
2
+ require 'peaches/finder'
3
+
4
+ require 'find'
5
+
6
+ module Peaches
7
+
8
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Peaches::Finder" do
4
+ let(:root) { "/Users/bradylove/Development/Gems/peaches" }
5
+ let(:finder) { Peaches::Finder.new(root) }
6
+
7
+ it "should find a toplevel file with a fuzzy name" do
8
+ finder.find("gem").should == ["Gemfile", "Gemfile.lock"]
9
+ end
10
+
11
+ it "should find a top level directory with a fuzzy name" do
12
+ finder.find("lb").should == ["lib/peaches/finder.rb", "lib/peaches/version.rb", "lib/peaches.rb", "spec/spec_helper.rb"]
13
+ end
14
+
15
+ it "should find a 2nd level file or directory with fuzzy name" do
16
+ finder.find("pches").should == ["bin/peaches", "lib/peaches/finder.rb", "lib/peaches/version.rb", "lib/peaches.rb", "spec/peaches/finder_spec.rb", "spec/peaches_spec.rb"]
17
+ end
18
+
19
+ it "should find a file without having the first letter of the file" do
20
+ finder.find("spec").should == ["spec/peaches/finder_spec.rb", "spec/peaches_spec.rb", "spec/spec_helper.rb"]
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Peaches do
4
+ it "it should have the correct version" do
5
+ Peaches::VERSION.should == '0.0.1'
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ #$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ #$LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rspec'
5
+ require 'peaches'
6
+ require 'rubygems'
7
+ require 'spork'
8
+
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ Spork.prefork do
12
+
13
+ end
14
+
15
+ Spork.each_run do
16
+ RSpec.configure do |config|
17
+
18
+ end
19
+ end
20
+
21
+
22
+
23
+
24
+
metadata ADDED
@@ -0,0 +1,179 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: peaches
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brady Love
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70147651457580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.8.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70147651457580
25
+ - !ruby/object:Gem::Dependency
26
+ name: yard
27
+ requirement: &70147651456320 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.7.5
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70147651456320
36
+ - !ruby/object:Gem::Dependency
37
+ name: guard-rspec
38
+ requirement: &70147651455460 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70147651455460
47
+ - !ruby/object:Gem::Dependency
48
+ name: pry
49
+ requirement: &70147651454580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70147651454580
58
+ - !ruby/object:Gem::Dependency
59
+ name: pry-doc
60
+ requirement: &70147651453580 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70147651453580
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry_debug
71
+ requirement: &70147651452060 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70147651452060
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-spork
82
+ requirement: &70147651451240 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70147651451240
91
+ - !ruby/object:Gem::Dependency
92
+ name: bundler
93
+ requirement: &70147651444120 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ~>
97
+ - !ruby/object:Gem::Version
98
+ version: 1.0.21
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70147651444120
102
+ - !ruby/object:Gem::Dependency
103
+ name: jeweler
104
+ requirement: &70147651443220 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.5.2
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70147651443220
113
+ - !ruby/object:Gem::Dependency
114
+ name: simplecov
115
+ requirement: &70147651442560 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *70147651442560
124
+ description: write a description
125
+ email: love.brady@gmail.com
126
+ executables:
127
+ - peaches
128
+ extensions: []
129
+ extra_rdoc_files:
130
+ - LICENSE.txt
131
+ - README.md
132
+ files:
133
+ - .document
134
+ - Gemfile
135
+ - Gemfile.lock
136
+ - Guardfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - VERSION
141
+ - bin/peaches
142
+ - lib/peaches.rb
143
+ - lib/peaches/finder.rb
144
+ - lib/peaches/version.rb
145
+ - spec/peaches/finder_spec.rb
146
+ - spec/peaches_spec.rb
147
+ - spec/spec_helper.rb
148
+ homepage: http://github.com/bradylove/peaches
149
+ licenses:
150
+ - MIT
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ segments:
162
+ - 0
163
+ hash: 3771765951699611876
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.10
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: A simple fuzzy file finder written in Ruby
176
+ test_files:
177
+ - spec/peaches/finder_spec.rb
178
+ - spec/peaches_spec.rb
179
+ - spec/spec_helper.rb