reverserequire 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/README.txt +7 -7
- data/lib/reverse_require/extensions/kernel.rb +5 -13
- data/lib/reverse_require/gems.rb +14 -16
- data/lib/reverse_require/reverse_require.rb +16 -0
- data/lib/reverse_require/version.rb +1 -1
- metadata +6 -6
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
=
|
1
|
+
= reverse_require
|
2
2
|
|
3
|
-
* http://
|
3
|
+
* http://rubyforge.org/projects/reverserequire/
|
4
4
|
* Postmodern Modulus III
|
5
5
|
|
6
6
|
== DESCRIPTION:
|
7
7
|
|
8
|
-
|
9
|
-
certain RubyGem and contain the specified path. Using
|
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
10
|
can allow others to easily extend the functionality of a RubyGem. Simply add
|
11
|
-
|
11
|
+
reverse_require into the code of your RubyGem:
|
12
12
|
|
13
13
|
reverse_require 'my_gem', 'some/path'
|
14
14
|
|
15
15
|
Then other gems which depend upon +my_gem+ merely have to provide
|
16
16
|
<tt>some/path</tt> within their <tt>lib/</tt> directory, and
|
17
|
-
|
17
|
+
reverse_require will load them all at run-time. This ability makes
|
18
18
|
designing plug-in systems for a RubyGem trivial.
|
19
19
|
|
20
20
|
== FEATURES/PROBLEMS:
|
@@ -27,7 +27,7 @@ designing plug-in systems for a RubyGem trivial.
|
|
27
27
|
|
28
28
|
== INSTALL:
|
29
29
|
|
30
|
-
$ sudo gem install
|
30
|
+
$ sudo gem install reverserequire
|
31
31
|
|
32
32
|
== LICENSE:
|
33
33
|
|
@@ -2,20 +2,12 @@ require 'reverse_require/reverse_require'
|
|
2
2
|
|
3
3
|
module Kernel
|
4
4
|
#
|
5
|
-
# Requires
|
6
|
-
# _ruby_gem_ and
|
7
|
-
# If no gems contain the specified _sub_path_
|
8
|
-
#
|
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
9
|
#
|
10
10
|
def reverse_require(ruby_gem,sub_path)
|
11
|
-
|
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)
|
11
|
+
ReverseRequire.require_for(ReverseRequire.gems_of(ruby_gem),sub_path)
|
20
12
|
end
|
21
13
|
end
|
data/lib/reverse_require/gems.rb
CHANGED
@@ -2,23 +2,21 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
module ReverseRequire
|
4
4
|
class Gems < Hash
|
5
|
-
|
6
5
|
#
|
7
6
|
# Creates a new Gems object containing the gems which depend upon
|
8
7
|
# the RubyGem of the specified _name_.
|
9
8
|
#
|
10
9
|
def self.depending_on(name)
|
11
10
|
name = name.to_s
|
12
|
-
gems = Gems.new
|
13
|
-
|
14
11
|
spec_dir = File.join(Gem.dir,'specifications')
|
15
|
-
|
16
|
-
|
17
|
-
all_gems.each do |path,gem|
|
18
|
-
deps = gem.dependencies.map { |dep| dep.name }
|
12
|
+
gems = Gems.new
|
19
13
|
|
14
|
+
Gem::SourceIndex.from_installed_gems(spec_dir).each do |path,gem_spec|
|
15
|
+
deps = gem_spec.dependencies.map { |dep| dep.name }
|
16
|
+
|
20
17
|
if deps.include?(name)
|
21
|
-
|
18
|
+
gem_path = File.expand_path(File.join(Gem.dir,'gems',path))
|
19
|
+
gems[gem_path] = gem_spec
|
22
20
|
end
|
23
21
|
end
|
24
22
|
|
@@ -32,9 +30,9 @@ module ReverseRequire
|
|
32
30
|
def select(&block)
|
33
31
|
gems = Gems.new
|
34
32
|
|
35
|
-
each do |
|
36
|
-
if block.call(
|
37
|
-
gems[
|
33
|
+
each do |path,gem_spec|
|
34
|
+
if block.call(path,gem_spec)
|
35
|
+
gems[path] = gem_spec
|
38
36
|
end
|
39
37
|
end
|
40
38
|
|
@@ -49,9 +47,9 @@ module ReverseRequire
|
|
49
47
|
def map(&block)
|
50
48
|
mapped = []
|
51
49
|
|
52
|
-
each do |
|
50
|
+
each do |path,gem_spec|
|
53
51
|
if block
|
54
|
-
mapped << block.call(
|
52
|
+
mapped << block.call(path,gem_spec)
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
@@ -62,14 +60,14 @@ module ReverseRequire
|
|
62
60
|
# Returns a new Gems object containing the gems which contain the
|
63
61
|
# specified _sub_path_.
|
64
62
|
#
|
65
|
-
# gems.
|
63
|
+
# gems.with_path('some/path') # => {...}
|
66
64
|
#
|
67
|
-
def
|
65
|
+
def with_path(sub_path)
|
68
66
|
if File.extname(sub_path).empty?
|
69
67
|
sub_path += '.rb'
|
70
68
|
end
|
71
69
|
|
72
|
-
select do |
|
70
|
+
select do |path,gem_spec|
|
73
71
|
File.exists?(File.expand_path(File.join(path,sub_path)))
|
74
72
|
end
|
75
73
|
end
|
@@ -8,4 +8,20 @@ module ReverseRequire
|
|
8
8
|
def ReverseRequire.gems_of(name)
|
9
9
|
Gems.depending_on(name)
|
10
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
|
11
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reverserequire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern Modulus III
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-04-
|
12
|
+
date: 2008-04-24 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 1.5.1
|
23
23
|
version:
|
24
|
-
description: "
|
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
25
|
email:
|
26
26
|
- postmodern.mod3@gmail.com
|
27
27
|
executables: []
|
@@ -44,7 +44,7 @@ files:
|
|
44
44
|
- lib/reverse_require/gems.rb
|
45
45
|
- lib/reverse_require/reverse_require.rb
|
46
46
|
has_rdoc: true
|
47
|
-
homepage: http://
|
47
|
+
homepage: http://rubyforge.org/projects/reverserequire/
|
48
48
|
post_install_message:
|
49
49
|
rdoc_options:
|
50
50
|
- --main
|
@@ -66,9 +66,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
requirements: []
|
67
67
|
|
68
68
|
rubyforge_project: reverserequire
|
69
|
-
rubygems_version: 1.1.
|
69
|
+
rubygems_version: 1.1.1
|
70
70
|
signing_key:
|
71
71
|
specification_version: 2
|
72
|
-
summary:
|
72
|
+
summary: reverse_require requires specific files from the gems which depend on a certain RubyGem and contain the specified path
|
73
73
|
test_files:
|
74
74
|
- test/test_agates.rb
|