fynd 0.1.2 → 0.1.3

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.
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
- # Fynd
1
+ GNU find is too slow. Let's make it slower by rewriting it in Ruby.
2
2
 
3
- I found GNU find to be slow, so I made it slower by rewriting it in Ruby.
4
-
5
- Fynd is heavily inspired by the, uh... find command, I guess.
3
+ Files in Fynd are lazy-loaded, much like ActiveRecord. Fynd expressions aren't called until you call `#files`. Fynd is heavily inspired by the, uh... find command, I guess.
6
4
 
7
5
  ## Is it any good?
8
6
 
@@ -54,4 +52,4 @@ end
54
52
  2. Create your feature branch (`git checkout -b my-new-feature`)
55
53
  3. Commit your changes (`git commit -am 'Add some feature'`)
56
54
  4. Push to the branch (`git push origin my-new-feature`)
57
- 5. Create new Pull Request
55
+ 5. Create new Pull Request
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.dirname(__FILE__) + '/../lib' unless $:.include?(File.dirname(__FILE__) + '/../lib/')
4
+
5
+ require 'fynd'
6
+
7
+ # Set up a bunch of test directories
8
+
9
+ require 'fileutils'
10
+ include FileUtils
11
+
12
+ test_dir = "/tmp/fynd_tests"
13
+
14
+ puts "=> making test dir #{test_dir}"
15
+ mkdir_p test_dir
16
+
17
+ # %w( 5 10 50 100 500 1000 5000 10000 ).each do |count|
18
+ %w( 5 10 50 100 500 1000 5000 10000 ).each do |count|
19
+ puts "=> filling #{test_dir}/#{count} with #{count} files"
20
+ mkdir_p "#{test_dir}/#{count}"
21
+ (1..count.to_i).each do |i|
22
+ touch "#{test_dir}/#{count}/#{i}"
23
+ end
24
+
25
+ Benchmark.bmbm(10) do |x|
26
+ x.report(:find) do
27
+ puts %x[ find #{test_dir}/#{count} -type f|wc -l ]
28
+ end
29
+
30
+ x.report(:fynd) do
31
+ puts Fynd.find(File.join(test_dir, count)).type(:f).files.count
32
+ end
33
+ end
34
+
35
+ puts "=> cleaning up test files"
36
+ rm_rf test_dir
37
+ puts
38
+ puts
39
+ end
40
+
41
+ # search a directory with a fairly large number of files. (over 100,000)
42
+
43
+
44
+
@@ -7,11 +7,12 @@ module Fynd
7
7
  class Criteria
8
8
  extend Forwardable
9
9
 
10
- attr_accessor :sieve
10
+ attr_accessor :sieve, :paths
11
11
 
12
12
  def_delegators :@sieve, :collection, :conditions
13
13
 
14
14
  def initialize(*paths)
15
+ @paths = paths
15
16
  @sieve = Sieve.new
16
17
  @sieve.collection = []
17
18
  @sieve.conditions = {}
@@ -19,17 +20,8 @@ module Fynd
19
20
  @sieve.conditions['operators'] = {}
20
21
  @sieve.conditions['tests'] = {}
21
22
 
22
- # For every path...
23
- paths.each do |path|
24
- # Pull out all directories
25
- # dirs = Dir.glob(File.expand_path(path)).select { |f| File.lstat(f).directory? }
26
- # Shove all found files into the collection
27
- # @sieve.collection << Dir.glob(File.expand_path(path))
28
- @sieve.collection << Find.find(File.expand_path(path)).to_a
29
- end
30
-
31
23
  # Flatten it and strip out non-unique files
32
- @sieve.collection.flatten!.uniq!
24
+
33
25
  end
34
26
 
35
27
  # def find(*paths)
@@ -38,12 +30,15 @@ module Fynd
38
30
  # end
39
31
 
40
32
  def run
33
+ @sieve.collection = paths.map do |path|
34
+ Find.find(File.expand_path(path)).to_a
35
+ end.flatten.uniq
41
36
  sieve.run
42
37
  return sieve.files
43
38
  end
44
39
 
45
40
  def files
46
- files = sieve.run
41
+ files = run
47
42
 
48
43
  if block_given?
49
44
  yield files
@@ -1,3 +1,3 @@
1
1
  module Fynd
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fynd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-08 00:00:00.000000000 Z
12
+ date: 2012-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -40,6 +40,7 @@ files:
40
40
  - LICENSE.txt
41
41
  - README.md
42
42
  - Rakefile
43
+ - benchmarks/find_vs_fynd.rb
43
44
  - fynd.gemspec
44
45
  - lib/fynd.rb
45
46
  - lib/fynd/actions.rb
@@ -64,7 +65,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
65
  version: '0'
65
66
  segments:
66
67
  - 0
67
- hash: 4151080051906730584
68
+ hash: -415099237484484251
68
69
  required_rubygems_version: !ruby/object:Gem::Requirement
69
70
  none: false
70
71
  requirements:
@@ -73,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
74
  version: '0'
74
75
  segments:
75
76
  - 0
76
- hash: 4151080051906730584
77
+ hash: -415099237484484251
77
78
  requirements: []
78
79
  rubyforge_project:
79
80
  rubygems_version: 1.8.24