path2 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +20 -0
  2. data/README.md +1 -0
  3. data/lib/path2.rb +69 -0
  4. metadata +47 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Bryan Goines
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 @@
1
+ Experimenting
data/lib/path2.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'thread'
2
+
3
+ class Path
4
+
5
+ def initialize(*args)
6
+ @id = generate_id
7
+ @self = "path2_#{@id}"
8
+ @semaphore = Mutex.new
9
+ @entries = build_entries(*args)
10
+ Thread.current[@self] = {}
11
+ end
12
+
13
+ def find(arg)
14
+ cache("find_#{arg}") do
15
+ grep(/#{arg}/)
16
+ end
17
+ end
18
+
19
+ def grep(pattern)
20
+ entries.grep(pattern)
21
+ end
22
+
23
+ def entries
24
+ @entries ||= []
25
+ end
26
+
27
+ def push(*paths)
28
+ @entries.concat(build_entries(*paths)).uniq!
29
+ end
30
+
31
+ def pop(*args)
32
+ args.each do |x|
33
+ @entries.delete_if {|y| File.expand_path(x) == y }
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def dir(path)
40
+ Dir["#{path}/**/*"]
41
+ end
42
+
43
+ def build_entries(*paths)
44
+ @semaphore.synchronize {
45
+ paths.map{|path| dir(File.expand_path(path)) }.flatten.uniq
46
+ }
47
+ end
48
+
49
+ def cache(name, &block)
50
+ _thread(name) || _thread(name, &block)
51
+ end
52
+
53
+ def _thread(name, &block)
54
+ if block_given?
55
+ Thread.current[@self][name] = block.call
56
+ else
57
+ Thread.current[@self][name]
58
+ end
59
+ end
60
+
61
+ def generate_id
62
+ Time.now.to_i
63
+ end
64
+
65
+ end
66
+
67
+ def Path(*args)
68
+ Path.new(*args)
69
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: path2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bryan Goines
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description:
15
+ email: bryann83@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - LICENSE
22
+ - lib/path2.rb
23
+ homepage: http://github.com/bry4n/path2
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.11
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: ! '...'
47
+ test_files: []