reverse-require 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,9 @@
1
+ === 0.1.0 / 2008-04-24
2
+
3
+ * Fixed a bug where the paths of RubyGems were not being saved, preventing
4
+ reverse_require from properly loading files from gems.
5
+
6
+ === 0.0.9 / 2008-04-13
7
+
8
+ * Initial release.
9
+
data/Manifest.txt ADDED
@@ -0,0 +1,10 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/reverse_require.rb
6
+ lib/reverse_require/version.rb
7
+ lib/reverse_require/extensions.rb
8
+ lib/reverse_require/extensions/kernel.rb
9
+ lib/reverse_require/gems.rb
10
+ lib/reverse_require/reverse_require.rb
data/README.txt ADDED
@@ -0,0 +1,55 @@
1
+ = ReverseRequire
2
+
3
+ * http://reverserequire.rubyforge.org/
4
+ * Postmodern Modulus III (postmodern.mod3@gmail.com)
5
+
6
+ == DESCRIPTION:
7
+
8
+ reverse_require requires specific files from the gems which depend on a
9
+ certain RubyGem and contain the specified path. Using reverse_require one
10
+ can allow others to easily extend the functionality of a RubyGem. Simply add
11
+ reverse_require into the code of your RubyGem:
12
+
13
+ reverse_require 'my_gem', 'some/path'
14
+
15
+ Then other gems which depend upon +my_gem+ merely have to provide
16
+ <tt>some/path</tt> within their <tt>lib/</tt> directory, and
17
+ reverse_require will load them all at run-time. This ability makes
18
+ designing plug-in systems for a RubyGem trivial.
19
+
20
+ == FEATURES/PROBLEMS:
21
+
22
+ * Require files from all the related gems of a RubyGem.
23
+
24
+ == REQUIREMENTS:
25
+
26
+ * RubyGems
27
+
28
+ == INSTALL:
29
+
30
+ $ sudo gem install reverserequire
31
+
32
+ == LICENSE:
33
+
34
+ The MIT License
35
+
36
+ Copyright (c) 2008 Hal Brodigan
37
+
38
+ Permission is hereby granted, free of charge, to any person obtaining
39
+ a copy of this software and associated documentation files (the
40
+ 'Software'), to deal in the Software without restriction, including
41
+ without limitation the rights to use, copy, modify, merge, publish,
42
+ distribute, sublicense, and/or sell copies of the Software, and to
43
+ permit persons to whom the Software is furnished to do so, subject to
44
+ the following conditions:
45
+
46
+ The above copyright notice and this permission notice shall be
47
+ included in all copies or substantial portions of the Software.
48
+
49
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
50
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
51
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
52
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
53
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
54
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
55
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/reverse_require/version.rb'
6
+
7
+ Hoe.new('reverse-require', ReverseRequire::VERSION) do |p|
8
+ p.rubyforge_name = 'reverserequire'
9
+ p.developer('Postmodern Modulus III','postmodern.mod3@gmail.com')
10
+ p.remote_rdoc_dir = ''
11
+ end
12
+
13
+ # vim: syntax=Ruby
@@ -0,0 +1,3 @@
1
+ require 'reverse_require/reverse_require'
2
+ require 'reverse_require/extensions'
3
+ require 'reverse_require/version'
@@ -0,0 +1 @@
1
+ require 'reverse_require/extensions/kernel'
@@ -0,0 +1,13 @@
1
+ require 'reverse_require/reverse_require'
2
+
3
+ module Kernel
4
+ #
5
+ # Requires certain files from the gems which depend on the
6
+ # specified _ruby_gem_ and contain the specified _sub_path_.
7
+ # If no gems contain the specified _sub_path_, +false+ will be
8
+ # returned.
9
+ #
10
+ def reverse_require(ruby_gem,sub_path)
11
+ ReverseRequire.require_for(ReverseRequire.gems_of(ruby_gem),sub_path)
12
+ end
13
+ end
@@ -0,0 +1,76 @@
1
+ require 'rubygems'
2
+
3
+ module ReverseRequire
4
+ class Gems < Hash
5
+ #
6
+ # Creates a new Gems object containing the gems which depend upon
7
+ # the RubyGem of the specified _name_.
8
+ #
9
+ def self.depending_on(name)
10
+ name = name.to_s
11
+ spec_dir = File.join(Gem.dir,'specifications')
12
+ gems = Gems.new
13
+
14
+ Gem::SourceIndex.from_installed_gems(spec_dir).each do |path,gem_spec|
15
+ deps = gem_spec.dependencies.map { |dep| dep.name }
16
+
17
+ if deps.include?(name)
18
+ gem_path = File.expand_path(File.join(Gem.dir,'gems',path))
19
+ gems[gem_path] = gem_spec
20
+ end
21
+ end
22
+
23
+ return gems
24
+ end
25
+
26
+ #
27
+ # Returns a new Gems object containing the names and paths from the
28
+ # gems which match the specified _block_.
29
+ #
30
+ def select(&block)
31
+ gems = Gems.new
32
+
33
+ each do |path,gem_spec|
34
+ if block.call(path,gem_spec)
35
+ gems[path] = gem_spec
36
+ end
37
+ end
38
+
39
+ return gems
40
+ end
41
+
42
+ #
43
+ # Invokes the given _block_ once for each name and path of the gems.
44
+ # Returns an +Array+ containing the values returned by the _block_.
45
+ # If no _block_ is given, an empty +Array+ will be returned.
46
+ #
47
+ def map(&block)
48
+ mapped = []
49
+
50
+ each do |path,gem_spec|
51
+ if block
52
+ mapped << block.call(path,gem_spec)
53
+ end
54
+ end
55
+
56
+ return mapped
57
+ end
58
+
59
+ #
60
+ # Returns a new Gems object containing the gems which contain the
61
+ # specified _sub_path_.
62
+ #
63
+ # gems.with_path('some/path') # => {...}
64
+ #
65
+ def with_path(sub_path)
66
+ if File.extname(sub_path).empty?
67
+ sub_path += '.rb'
68
+ end
69
+
70
+ select do |path,gem_spec|
71
+ File.exists?(File.expand_path(File.join(path,sub_path)))
72
+ end
73
+ end
74
+
75
+ end
76
+ end
@@ -0,0 +1,27 @@
1
+ require 'reverse_require/gems'
2
+
3
+ module ReverseRequire
4
+ #
5
+ # Returns a new Gems object containing the gems which depend upon
6
+ # the RubyGem of the specified _name_.
7
+ #
8
+ def ReverseRequire.gems_of(name)
9
+ Gems.depending_on(name)
10
+ end
11
+
12
+ #
13
+ # Requires certain files from the _gems_ that contain the specified
14
+ # _sub_path_. If no gems contain the specified _sub_path_, +false+ will be
15
+ # returned.
16
+ #
17
+ def ReverseRequire.require_for(gems,sub_path)
18
+ lib_path = File.join('lib',sub_path)
19
+
20
+ was_loaded = gems.with_path(lib_path).map do |path,gem_spec|
21
+ gem(gem_spec.name,gem_spec.version)
22
+ require File.expand_path(File.join(path,lib_path))
23
+ end
24
+
25
+ return was_loaded.include?(true)
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module ReverseRequire
2
+ VERSION = '0.1.0'
3
+ end
File without changes
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reverse-require
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Postmodern Modulus III
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-02 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.7.0
24
+ version:
25
+ description: "reverse_require requires specific files from the gems which depend on a certain RubyGem and contain the specified path. Using reverse_require one can allow others to easily extend the functionality of a RubyGem. Simply add reverse_require into the code of your RubyGem: reverse_require 'my_gem', 'some/path' Then other gems which depend upon +my_gem+ merely have to provide <tt>some/path</tt> within their <tt>lib/</tt> directory, and reverse_require will load them all at run-time. This ability makes designing plug-in systems for a RubyGem trivial."
26
+ email:
27
+ - postmodern.mod3@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - lib/reverse_require.rb
42
+ - lib/reverse_require/version.rb
43
+ - lib/reverse_require/extensions.rb
44
+ - lib/reverse_require/extensions/kernel.rb
45
+ - lib/reverse_require/gems.rb
46
+ - lib/reverse_require/reverse_require.rb
47
+ has_rdoc: true
48
+ homepage: http://reverserequire.rubyforge.org/
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --main
52
+ - README.txt
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ requirements: []
68
+
69
+ rubyforge_project: reverserequire
70
+ rubygems_version: 1.2.0
71
+ signing_key:
72
+ specification_version: 2
73
+ summary: reverse_require requires specific files from the gems which depend on a certain RubyGem and contain the specified path
74
+ test_files:
75
+ - test/test_agates.rb