reverserequire 0.0.9 → 0.1.0

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 CHANGED
@@ -1,3 +1,8 @@
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
+
1
6
  === 0.0.9 / 2008-04-13
2
7
 
3
8
  * Initial release.
data/README.txt CHANGED
@@ -1,20 +1,20 @@
1
- = Agate
1
+ = reverse_require
2
2
 
3
- * http://reverserequire.rubyforge.org/
3
+ * http://rubyforge.org/projects/reverserequire/
4
4
  * Postmodern Modulus III
5
5
 
6
6
  == DESCRIPTION:
7
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
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
- +reverse_require+ into the code of your RubyGem:
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
- +reverse_require+ will load them all at run-time. This ability makes
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 reverse_require
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 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.
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
- 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)
11
+ ReverseRequire.require_for(ReverseRequire.gems_of(ruby_gem),sub_path)
20
12
  end
21
13
  end
@@ -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
- 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 }
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
- gems[gem] = path
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 |name,path|
36
- if block.call(name,path)
37
- gems[name] = path
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 |name,path|
50
+ each do |path,gem_spec|
53
51
  if block
54
- mapped << block.call(name,path)
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.with('some/path') # => {...}
63
+ # gems.with_path('some/path') # => {...}
66
64
  #
67
- def with(sub_path)
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 |name,path|
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
@@ -1,3 +1,3 @@
1
1
  module ReverseRequire
2
- VERSION = '0.0.9'
2
+ VERSION = '0.1.0'
3
3
  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.9
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-13 00:00:00 -07:00
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: "+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."
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://reverserequire.rubyforge.org/
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.0
69
+ rubygems_version: 1.1.1
70
70
  signing_key:
71
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
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