reverserequire 0.0.9

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/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.9 / 2008-04-13
2
+
3
+ * Initial release.
4
+
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
+ = Agate
2
+
3
+ * http://reverserequire.rubyforge.org/
4
+ * Postmodern Modulus III
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 reverse_require
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,12 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/reverse_require/version.rb'
6
+
7
+ Hoe.new('reverserequire', ReverseRequire::VERSION) do |p|
8
+ p.rubyforge_name = 'reverserequire'
9
+ p.developer('Postmodern Modulus III','postmodern.mod3@gmail.com')
10
+ end
11
+
12
+ # vim: syntax=Ruby
@@ -0,0 +1,21 @@
1
+ require 'reverse_require/reverse_require'
2
+
3
+ module Kernel
4
+ #
5
+ # Requires all files from the gems which depend on the specified
6
+ # _ruby_gem_ and that contain the specified _sub_path_.
7
+ # If no gems contain the specified _sub_path_ a LoadError
8
+ # exception will be thrown.
9
+ #
10
+ def reverse_require(ruby_gem,sub_path)
11
+ lib_path = File.join('lib',sub_path)
12
+ gems = ReverseRequire.gems_of(ruby_gem)
13
+
14
+ was_loaded = gems.with(lib_path).map do |name,path|
15
+ gem name
16
+ require File.expand_path(File.join(path,lib_path))
17
+ end
18
+
19
+ return was_loaded.include?(true)
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ require 'reverse_require/extensions/kernel'
@@ -0,0 +1,78 @@
1
+ require 'rubygems'
2
+
3
+ module ReverseRequire
4
+ class Gems < Hash
5
+
6
+ #
7
+ # Creates a new Gems object containing the gems which depend upon
8
+ # the RubyGem of the specified _name_.
9
+ #
10
+ def self.depending_on(name)
11
+ name = name.to_s
12
+ gems = Gems.new
13
+
14
+ spec_dir = File.join(Gem.dir,'specifications')
15
+ all_gems = Gem::SourceIndex.from_installed_gems(spec_dir)
16
+
17
+ all_gems.each do |path,gem|
18
+ deps = gem.dependencies.map { |dep| dep.name }
19
+
20
+ if deps.include?(name)
21
+ gems[gem] = path
22
+ end
23
+ end
24
+
25
+ return gems
26
+ end
27
+
28
+ #
29
+ # Returns a new Gems object containing the names and paths from the
30
+ # gems which match the specified _block_.
31
+ #
32
+ def select(&block)
33
+ gems = Gems.new
34
+
35
+ each do |name,path|
36
+ if block.call(name,path)
37
+ gems[name] = path
38
+ end
39
+ end
40
+
41
+ return gems
42
+ end
43
+
44
+ #
45
+ # Invokes the given _block_ once for each name and path of the gems.
46
+ # Returns an +Array+ containing the values returned by the _block_.
47
+ # If no _block_ is given, an empty +Array+ will be returned.
48
+ #
49
+ def map(&block)
50
+ mapped = []
51
+
52
+ each do |name,path|
53
+ if block
54
+ mapped << block.call(name,path)
55
+ end
56
+ end
57
+
58
+ return mapped
59
+ end
60
+
61
+ #
62
+ # Returns a new Gems object containing the gems which contain the
63
+ # specified _sub_path_.
64
+ #
65
+ # gems.with('some/path') # => {...}
66
+ #
67
+ def with(sub_path)
68
+ if File.extname(sub_path).empty?
69
+ sub_path += '.rb'
70
+ end
71
+
72
+ select do |name,path|
73
+ File.exists?(File.expand_path(File.join(path,sub_path)))
74
+ end
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,11 @@
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
+ end
@@ -0,0 +1,3 @@
1
+ module ReverseRequire
2
+ VERSION = '0.0.9'
3
+ end
@@ -0,0 +1,3 @@
1
+ require 'reverse_require/reverse_require'
2
+ require 'reverse_require/extensions'
3
+ require 'reverse_require/version'
File without changes
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reverserequire
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.9
5
+ platform: ruby
6
+ authors:
7
+ - Postmodern Modulus III
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-13 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.5.1
23
+ version:
24
+ 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."
25
+ email:
26
+ - postmodern.mod3@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - lib/reverse_require.rb
41
+ - lib/reverse_require/version.rb
42
+ - lib/reverse_require/extensions.rb
43
+ - lib/reverse_require/extensions/kernel.rb
44
+ - lib/reverse_require/gems.rb
45
+ - lib/reverse_require/reverse_require.rb
46
+ has_rdoc: true
47
+ homepage: http://reverserequire.rubyforge.org/
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --main
51
+ - README.txt
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: reverserequire
69
+ rubygems_version: 1.1.0
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: +reverse_require+ requires specific files from the gems which depend on a certain RubyGem and contain the specified path
73
+ test_files:
74
+ - test/test_agates.rb