finder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.ruby ADDED
@@ -0,0 +1,50 @@
1
+ ---
2
+ source:
3
+ - ruby.yml
4
+ authors:
5
+ - name: Trans
6
+ email: transfire@gmail.com
7
+ copyrights:
8
+ - holder: Rubyworks
9
+ year: '2009'
10
+ license: BSD-2-Clause
11
+ replacements: []
12
+ alternatives: []
13
+ requirements:
14
+ - name: detroit
15
+ groups:
16
+ - build
17
+ development: true
18
+ - name: qed
19
+ groups:
20
+ - test
21
+ development: true
22
+ - name: ae
23
+ groups:
24
+ - test
25
+ development: true
26
+ dependencies: []
27
+ conflicts: []
28
+ repositories:
29
+ - uri: git://github.com/rubyworks/plugin.git
30
+ scm: git
31
+ name: upstream
32
+ resources:
33
+ home: http://rubyworks.github.com/finder
34
+ code: http://github.com/rubyworks/finder
35
+ mail: http://groups.google.com/rubyworks-mailinglist
36
+ extra: {}
37
+ load_path:
38
+ - lib
39
+ revision: 0
40
+ name: finder
41
+ title: Finder
42
+ version: 0.1.0
43
+ summary: Robust library file locator
44
+ created: '2009-11-24'
45
+ description: Finder is a general purpose file finder for Ruby. Finder can search RubyGems,
46
+ Roll libraries and Ruby's standard $LOAD_PATH and system data directory for the
47
+ active or the most current library files. It is especially useful for implementing
48
+ library-based plugin systems.
49
+ organization: rubyworks
50
+ date: '2012-02-11'
@@ -0,0 +1,7 @@
1
+ --title Finder
2
+ --output-dir doc
3
+ --private
4
+ --protected
5
+ lib/
6
+ -
7
+ [A-Z]*.*
@@ -0,0 +1,38 @@
1
+ = COPYRIGHT
2
+
3
+ == NOTICES
4
+
5
+ === Finder
6
+
7
+ Copyright:: (c) 2012 RubyWorks
8
+ License:: (r) BSD-2-Clause
9
+ Website:: http://rubyworks.github.com/finder
10
+
11
+ == LICENSES
12
+
13
+ === BSD-2-Clause License
14
+
15
+ Assay
16
+
17
+ Copyright (c) 2012 Rubyworks. All rights reserved.
18
+
19
+ Redistribution and use in source and binary forms, with or without
20
+ modification, are permitted provided that the following conditions are met:
21
+
22
+ 1. Redistributions of source code must retain the above copyright notice,
23
+ this list of conditions and the following disclaimer.
24
+
25
+ 2. Redistributions in binary form must reproduce the above copyright
26
+ notice, this list of conditions and the following disclaimer in the
27
+ documentation and/or other materials provided with the distribution.
28
+
29
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
30
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31
+ FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32
+ COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34
+ NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
36
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
37
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
38
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,12 @@
1
+ # RELEASE HISTORY
2
+
3
+ ## 0.1.0 / 2012-02-11
4
+
5
+ Finder is a new library built from the ashes of the old Plugin gem.
6
+ Along with a new more fitting name, it has more robust and expanded
7
+ capabilites!
8
+
9
+ Changes:
10
+
11
+ * Happy Rebirthday!
12
+
@@ -0,0 +1,46 @@
1
+ # Finder
2
+
3
+ [Homepage](http://rubyworks.github.com/finder) /
4
+ [Report Issue](http://github.com/rubyworks/finder/issues) /
5
+ [Development](http://github.com/rubyworks/finder) /
6
+ [Mailing List](http://groups.google.com/groups/rubyworks-mailinglist) /
7
+ [IRC Channel](irc://chat.us.freenode.net/rubyworks)
8
+
9
+ [![Build Status](https://secure.travis-ci.org/rubyworks/finder.png)](http://travis-ci.org/rubyworks/finder)
10
+
11
+
12
+ ## DESCRIPTION
13
+
14
+ Finder is a straight-forward file finder for searching Ruby library paths.
15
+ It can handle RubyGems, Rolls and Ruby's standard site locals. It is both
16
+ more flexible and more robust the using Gem.find_files or searching the
17
+ $LOAD_PATH manually.
18
+
19
+
20
+ ## INSTRUCTION
21
+
22
+ To find finders, simply provide a glob to the appropriate Finder function,
23
+ and it will return all matches found within current and/or most recent versions
24
+ of a library.
25
+
26
+ For example, a common use case is for a pluggable application is to require all
27
+ the finders found in library load paths:
28
+
29
+ require 'finder'
30
+
31
+ Find.load_path('myapp/*.rb').each do |file|
32
+ require(file)
33
+ end
34
+
35
+ Alternately you might load finders only as needed. For instance, if a command-line
36
+ option calls for it.
37
+
38
+
39
+ ## COPYRIGHTS
40
+
41
+ Copyright (c) 2009 Thomas Sawyer
42
+
43
+ Finder is release under the terms of the **BSD-2-Clause** license.
44
+
45
+ See COPYING for details.
46
+
@@ -0,0 +1 @@
1
+ require 'ae'
@@ -0,0 +1,3 @@
1
+ # add the fixtures directory to the $LOAD_PATH
2
+ $:.unshift(File.dirname(File.dirname(__FILE__)) + '/fixtures')
3
+
@@ -0,0 +1 @@
1
+ $proof = "plugin loading worked"
@@ -0,0 +1,34 @@
1
+ # Plugin Demonstrandum
2
+
3
+ To use the Finder library first we need to require it.
4
+
5
+ require 'finder'
6
+
7
+ Now use +Find.load+path+ to seach for a file pattern of our
8
+ choosing within library load paths.
9
+
10
+ files = Find.load_path('example.rb')
11
+ file = files.first
12
+
13
+ The +find+ method returns path name relative to the load path.
14
+
15
+ file.assert == 'example.rb'
16
+
17
+ We can use the `aboslute` option to get the full path.
18
+
19
+ files = Find.load_path('example.rb', :absolute=>true)
20
+ file = files.first
21
+
22
+ File.expand_path(file).assert == file
23
+ file.assert.end_with?('example.rb')
24
+
25
+ As with any Ruby script we can require it.
26
+
27
+ file = Find.load_path('example.rb').first
28
+ require file
29
+
30
+ Our example.rb script defines the global variable $proof.
31
+ We can see that it loaded just fine.
32
+
33
+ $proof.assert == "plugin loading worked"
34
+
@@ -0,0 +1,28 @@
1
+ require 'finder/find'
2
+
3
+ module Finder
4
+
5
+ # Current version.
6
+ VERSION = '0.1.0'
7
+
8
+ # Clean module that can be included elsewhere, to proved #path, #load_path
9
+ # and #data_path methods without including the Gem, Roll, and Site constants.
10
+ module Findable
11
+ def path(match, options={})
12
+ Find.path(match, options)
13
+ end
14
+
15
+ def load_path(match, options={})
16
+ Find.load_path(match, options)
17
+ end
18
+
19
+ def data_path(match, options={})
20
+ Find.data_path(match, options)
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ # Convenience shortcut.
27
+ Find = Finder::Find
28
+
@@ -0,0 +1,84 @@
1
+ require 'finder/roll'
2
+ require 'finder/gem'
3
+ require 'finder/site'
4
+
5
+ module Finder
6
+
7
+ # Find module is the main interface for Finder library.
8
+ #
9
+ module Find
10
+ extend self
11
+
12
+ # Find matching paths, searching through Rolled libraries, Gem-installed libraries
13
+ # and site locations in `$LOAD_PATH` and `RbConfig::CONFIG['datadir']`.
14
+ #
15
+ # @param [String] match
16
+ # File glob to match against.
17
+ #
18
+ # @example
19
+ # Find.path('lib/foo/*')
20
+ #
21
+ def path(glob, options={})
22
+ found = []
23
+ systems.each do |system|
24
+ found.concat system.path(match, options)
25
+ end
26
+ found.uniq
27
+ end
28
+
29
+ # Shortcut for #path.
30
+ #
31
+ # Plugin['syckle/*']
32
+ #
33
+ alias_method :[], :path
34
+
35
+ # Searching through Rolls, RubyGems and Site locations for matching
36
+ # load paths.
37
+ #
38
+ # @param [String] match
39
+ # File glob to match against.
40
+ #
41
+ # @example
42
+ # Find.load_path('bar/*')
43
+ #
44
+ def load_path(match, options={})
45
+ found = []
46
+ systems.each do |system|
47
+ found.concat system.load_path(match, options)
48
+ end
49
+ found.uniq
50
+ end
51
+
52
+ # Searching through Rolls, RubyGems and Site locations for matching
53
+ # data paths.
54
+ #
55
+ # @param [String] match
56
+ # File glob to match against.
57
+ #
58
+ # @example
59
+ # Find.data_path('bar/*')
60
+ #
61
+ def data_path(glob)
62
+ found = []
63
+ systems.each do |system|
64
+ found.concat system.data_path(match, options)
65
+ end
66
+ found.uniq
67
+ end
68
+
69
+ #
70
+ # List of supported library management systems.
71
+ #
72
+ def systems
73
+ @systems ||= (
74
+ systems = []
75
+ systems << Roll if defined?(::Library)
76
+ systems << Gem if defined?(::Gem)
77
+ systems << Site
78
+ systems
79
+ )
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,126 @@
1
+ module Finder
2
+ module Find
3
+
4
+ # RubyGems finder methods.
5
+ #
6
+ module Gem
7
+ extend self
8
+
9
+ #
10
+ # Search gems.
11
+ #
12
+ # @param [String] match
13
+ # The file glob to match.
14
+ #
15
+ # @param [Hash] options
16
+ # Search options.
17
+ #
18
+ # @return [Array<String>] List of absolute paths.
19
+ #
20
+ def path(match, options={})
21
+ matches = []
22
+ ::Gem::Specification.current_specs.each do |spec|
23
+ list = []
24
+ glob = File.join(spec.full_gem_path, match)
25
+ list = Dir[glob] #.map{ |f| f.untaint }
26
+ list = list.map{ |d| d.chomp('/') }
27
+ matches.concat(list)
28
+ # activate the library if activate flag
29
+ lib.activate if options[:activate] && !list.empty?
30
+ end
31
+ matches
32
+ end
33
+
34
+ #
35
+ # Search gem load paths.
36
+ #
37
+ # @param [String] match
38
+ # The file glob to match.
39
+ #
40
+ # @param [Hash] options
41
+ # Search options.
42
+ #
43
+ # @option options [true,false] :absolute
44
+ # Return absolute paths instead of relative to load path.
45
+ #
46
+ # @option options [true,false] :activate
47
+ # Activate the gems if it has matching files.
48
+ #
49
+ # @return [Array<String>] List of paths.
50
+ #
51
+ def load_path(match, options={})
52
+ matches = []
53
+ ::Gem::Specification.current_specs.each do |spec|
54
+ list = []
55
+ spec.require_paths.each do |path|
56
+ glob = File.join(spec.full_gem_path, path, match)
57
+ list = Dir[glob] #.map{ |f| f.untaint }
58
+ list = list.map{ |d| d.chomp('/') }
59
+ # return relative paths unless absolute flag
60
+ if not options[:absolute]
61
+ # the extra '' in File.join adds a '/' to the end of the path
62
+ list = list.map{ |f| f.sub(File.join(spec.full_gem_path, path, ''), '') }
63
+ end
64
+ matches.concat(list)
65
+ end
66
+ # activate the library if activate flag
67
+ lib.activate if options[:activate] && !list.empty?
68
+ end
69
+ matches
70
+ end
71
+
72
+ #
73
+ # Search gem data paths.
74
+ #
75
+ # @param [String] match
76
+ # The file glob to match.
77
+ #
78
+ # @param [Hash] options
79
+ # Search options.
80
+ #
81
+ # @return [Array<String>] List of absolute paths.
82
+ #
83
+ def data_path(match, options={})
84
+ matches = []
85
+ ::Gem::Specification.current_specs.each do |spec|
86
+ list = []
87
+ glob = File.join(spec.full_gem_path, 'data', match)
88
+ list = Dir[glob] #.map{ |f| f.untaint }
89
+ list = list.map{ |d| d.chomp('/') }
90
+ matches.concat(list)
91
+ # activate the library if activate flag
92
+ lib.activate if options[:activate] && !list.empty?
93
+ end
94
+ matches
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+ end
101
+
102
+
103
+ module Gem
104
+
105
+ # Gem::Specification is extended to support `current_specs` method.
106
+ class Specification
107
+
108
+ # Return a list of active specs or latest version of spec if not active.
109
+ def self.current_specs
110
+ named = Hash.new{|h,k| h[k] = [] }
111
+ each{ |spec| named[spec.name] << spec }
112
+ list = []
113
+ named.each do |name, vers|
114
+ if spec = vers.find{ |s| s.activated? }
115
+ list << spec
116
+ else
117
+ spec = vers.max{ |a,b| a.version <=> b.version }
118
+ list << spec
119
+ end
120
+ end
121
+ return list
122
+ end
123
+
124
+ end
125
+
126
+ end
@@ -0,0 +1,87 @@
1
+ module Finder
2
+ module Find
3
+
4
+ # Library finder methods.
5
+ #
6
+ module Roll
7
+ extend self
8
+
9
+ #
10
+ # Search for current or latest files within a library.
11
+ #
12
+ # @param [String] match
13
+ # The file glob to match.
14
+ #
15
+ # @param [Hash] options
16
+ # Search options.
17
+ #
18
+ # @return [Array<String>] List of paths.
19
+ #
20
+ def path(match, options={})
21
+ return [] unless defined?(::Library)
22
+ matches = []
23
+ ::Library.ledger.each do |name, lib|
24
+ lib = lib.sort.first if Array===lib
25
+ find = File.join(lib.location, match)
26
+ list = Dir.glob(find)
27
+ list = list.map{ |d| d.chomp('/') }
28
+ matches.concat(list)
29
+ end
30
+ matches
31
+ end
32
+
33
+ #
34
+ # Search Roll system for current or latest library files. This is useful
35
+ # for plugin loading.
36
+ #
37
+ # This only searches activated libraries or the most recent version
38
+ # of any given library.
39
+ #
40
+ # @param [String] match
41
+ # The file glob to match.
42
+ #
43
+ # @param [Hash] options
44
+ # Search options.
45
+ #
46
+ # @option options [true,false] :absolute
47
+ # Return absolute paths instead of relative to load path.
48
+ #
49
+ # @option options [true,false] :activate
50
+ # Activate the library if it has matching files.
51
+ #
52
+ # @return [Array<String>] List of paths.
53
+ #
54
+ def load_path(match, options={})
55
+ matches = []
56
+ ::Library.ledger.each do |name, lib|
57
+ list = []
58
+ lib = lib.sort.first if Array===lib
59
+ lib.loadpath.each do |path|
60
+ find = File.join(lib.location, path, match)
61
+ list = Dir.glob(find)
62
+ list = list.map{ |d| d.chomp('/') }
63
+ # return relative load path unless absolte flag
64
+ if not options[:absolute]
65
+ # the extra '' in File.join adds a '/' to the end of the path
66
+ list = list.map{ |f| f.sub(File.join(lib.location, path, ''), '') }
67
+ end
68
+ matches.concat(list)
69
+ end
70
+ # activate the library if activate flag
71
+ lib.activate if options[:activate] && !list.empty?
72
+ end
73
+ matches
74
+ end
75
+
76
+ ## Search rolls for current or latest libraries.
77
+ ##
78
+ ##def load_path(match, options={})
79
+ # return [] unless defined?(::Library)
80
+ # #::Library.search_latest(match)
81
+ # ::Library.find_files(match)
82
+ #end
83
+
84
+ end
85
+
86
+ end
87
+ end
@@ -0,0 +1,72 @@
1
+ require 'rbconfig'
2
+
3
+ module Finder
4
+ module Find
5
+
6
+ # System location finder methods.
7
+ #
8
+ module Site
9
+ extend self
10
+
11
+ DATA_PATH = RbConfig::CONFIG['datadir']
12
+
13
+ #
14
+ # Search load path for matching patterns.
15
+ #
16
+ # @param [String] match
17
+ # The file glob to match.
18
+ #
19
+ # @param [Hash] options
20
+ # Search options.
21
+ #
22
+ # @return [Array<String>] List of paths.
23
+ #
24
+ def path(match, options={})
25
+ found = []
26
+ $LOAD_PATH.uniq.map do |path|
27
+ list = Dir.glob(File.join(File.expand_path(path), match))
28
+ list = list.map{ |d| d.chomp('/') }
29
+ found.concat(list)
30
+ end
31
+ found.concat(data_path(match, options))
32
+ found
33
+ end
34
+
35
+ # Search load path for matching patterns.
36
+ #
37
+ # @param [String] match
38
+ # The file glob to match.
39
+ #
40
+ # @param [Hash] options
41
+ # Search options.
42
+ #
43
+ # @option options [true,false] :absolute
44
+ # Return absolute paths instead of relative to load path.
45
+ #
46
+ # @return [Array<String>] List of paths.
47
+ #
48
+ def load_path(match, options={})
49
+ found = []
50
+ $LOAD_PATH.uniq.map do |path|
51
+ list = Dir.glob(File.join(File.expand_path(path), match))
52
+ list = list.map{ |d| d.chomp('/') }
53
+ # return relative load path unless absolute flag
54
+ if not options[:absolute]
55
+ # the extra '' in File.join adds a '/' to the end of the path
56
+ list = list.map{ |f| f.sub(File.join(path, ''), '') }
57
+ end
58
+ found.concat(list)
59
+ end
60
+ found
61
+ end
62
+
63
+ # Search data path.
64
+ #
65
+ def data_path(match, options={})
66
+ Dir.glob(File.join(DATA_PATH, match)).uniq
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: finder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Trans
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: detroit
16
+ requirement: &20870760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *20870760
25
+ - !ruby/object:Gem::Dependency
26
+ name: qed
27
+ requirement: &20870140 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *20870140
36
+ - !ruby/object:Gem::Dependency
37
+ name: ae
38
+ requirement: &20869620 !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: *20869620
47
+ description: Finder is a general purpose file finder for Ruby. Finder can search RubyGems,
48
+ Roll libraries and Ruby's standard $LOAD_PATH and system data directory for the
49
+ active or the most current library files. It is especially useful for implementing
50
+ library-based plugin systems.
51
+ email:
52
+ - transfire@gmail.com
53
+ executables: []
54
+ extensions: []
55
+ extra_rdoc_files:
56
+ - COPYING.rdoc
57
+ - HISTORY.md
58
+ - README.md
59
+ files:
60
+ - .ruby
61
+ - .yardopts
62
+ - demo/applique/ae.rb
63
+ - demo/applique/helper.rb
64
+ - demo/fixtures/example.rb
65
+ - demo/load_path.md
66
+ - lib/finder/find.rb
67
+ - lib/finder/gem.rb
68
+ - lib/finder/roll.rb
69
+ - lib/finder/site.rb
70
+ - lib/finder.rb
71
+ - HISTORY.md
72
+ - README.md
73
+ - COPYING.rdoc
74
+ homepage: http://rubyworks.github.com/finder
75
+ licenses:
76
+ - BSD-2-Clause
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 1.8.11
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Robust library file locator
99
+ test_files: []