reverse-require 0.1.2 → 0.2.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 +7 -0
- data/Manifest.txt +3 -2
- data/README.txt +13 -12
- data/Rakefile +1 -1
- data/TODO.txt +2 -0
- data/lib/reverse_require.rb +0 -1
- data/lib/reverse_require/exceptions.rb +1 -0
- data/lib/reverse_require/exceptions/rubygems_version_exception.rb +4 -0
- data/lib/reverse_require/extensions/kernel.rb +29 -7
- data/lib/reverse_require/version.rb +1 -1
- metadata +11 -9
- data/lib/reverse_require/gems.rb +0 -147
- data/lib/reverse_require/reverse_require.rb +0 -38
data/History.txt
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
=== 0.2.0 / 2008-11-23
|
2
|
+
|
3
|
+
* Use the new Gem.find_files method provided by RubyGems >= 1.3.0. Using
|
4
|
+
Gem.find_files in reverse_require has greatly decreased the executation
|
5
|
+
time of reverse_require.
|
6
|
+
* Added the require_all method, which is an alias to reverse_require.
|
7
|
+
|
1
8
|
=== 0.1.2 / 2008-10-22
|
2
9
|
|
3
10
|
* Fixed a bug where ReverseRequire.require_for would try to activate
|
data/Manifest.txt
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
History.txt
|
2
2
|
Manifest.txt
|
3
3
|
README.txt
|
4
|
+
TODO.txt
|
4
5
|
Rakefile
|
5
6
|
lib/reverse_require.rb
|
6
7
|
lib/reverse_require/version.rb
|
8
|
+
lib/reverse_require/exceptions.rb
|
9
|
+
lib/reverse_require/exceptions/rubygems_version_exception.rb
|
7
10
|
lib/reverse_require/extensions.rb
|
8
11
|
lib/reverse_require/extensions/kernel.rb
|
9
|
-
lib/reverse_require/gems.rb
|
10
|
-
lib/reverse_require/reverse_require.rb
|
data/README.txt
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
= ReverseRequire
|
2
2
|
|
3
3
|
* http://reverserequire.rubyforge.org/
|
4
|
-
* Postmodern
|
4
|
+
* Postmodern (postmodern.mod3 at gmail.com)
|
5
5
|
|
6
6
|
== DESCRIPTION:
|
7
7
|
|
8
|
-
reverse_require
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
reverse_require will require all files ending with a specified path from
|
9
|
+
within previously installed RubyGems. By using reverse_require in your
|
10
|
+
code-base, it allows developers to extend the functionality of your
|
11
|
+
code-base, by merely adding specially named files to their own RubyGems.
|
12
|
+
Simply use reverse_require in the code-base that you'd like to be extendable:
|
12
13
|
|
13
|
-
reverse_require '
|
14
|
+
reverse_require 'some/path'
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
designing plug-in systems for a RubyGem trivial.
|
16
|
+
The <tt>some/path.rb</tt> files within the <tt>lib/</tt> directories of
|
17
|
+
other RubyGems will then be loaded. This functionality makes designing
|
18
|
+
plug-in systems ontop of RubyGems trivial.
|
19
19
|
|
20
20
|
== FEATURES/PROBLEMS:
|
21
21
|
|
22
|
-
* Require files
|
22
|
+
* Require files ending with a specified path from previously installed
|
23
|
+
RubyGems.
|
23
24
|
|
24
25
|
== REQUIREMENTS:
|
25
26
|
|
26
|
-
* RubyGems
|
27
|
+
* RubyGems >= 1.3.0
|
27
28
|
|
28
29
|
== INSTALL:
|
29
30
|
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require './lib/reverse_require/version.rb'
|
|
6
6
|
|
7
7
|
Hoe.new('reverse-require', ReverseRequire::VERSION) do |p|
|
8
8
|
p.rubyforge_name = 'reverserequire'
|
9
|
-
p.developer('Postmodern
|
9
|
+
p.developer('Postmodern','postmodern.mod3@gmail.com')
|
10
10
|
p.remote_rdoc_dir = ''
|
11
11
|
end
|
12
12
|
|
data/TODO.txt
ADDED
data/lib/reverse_require.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'reverse_require/exceptions/rubygems_version_exception'
|
@@ -1,13 +1,35 @@
|
|
1
|
-
require 'reverse_require/
|
1
|
+
require 'reverse_require/exceptions/rubygems_version_exception'
|
2
2
|
|
3
3
|
module Kernel
|
4
4
|
#
|
5
|
-
# Requires
|
6
|
-
# specified
|
7
|
-
#
|
8
|
-
# returned.
|
5
|
+
# Requires all files from previously installed RubyGems that
|
6
|
+
# end with the specified _path_. If no RubyGems contain the
|
7
|
+
# specified _path_, +false+ will be returned.
|
9
8
|
#
|
10
|
-
|
11
|
-
|
9
|
+
# reverse_require 'ronin/models'
|
10
|
+
# # => true
|
11
|
+
#
|
12
|
+
def reverse_require(path)
|
13
|
+
major, minor, rev = Gem::RubyGemsVersion.split('.').map { |i| i.to_i }
|
14
|
+
|
15
|
+
if (major == 1 && minor == 2)
|
16
|
+
raise(ReverseRequire::RubyGemsVersionException,"RubyGems >= 1.3.0 is required for reverse_require",caller)
|
17
|
+
end
|
18
|
+
|
19
|
+
was_loaded = false
|
20
|
+
|
21
|
+
Gem.find_files(path).reverse_each do |path|
|
22
|
+
begin
|
23
|
+
if File.file?(path)
|
24
|
+
was_loaded ||= require path
|
25
|
+
end
|
26
|
+
rescue
|
27
|
+
next
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
return was_loaded
|
12
32
|
end
|
33
|
+
|
34
|
+
alias require_all reverse_require
|
13
35
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reverse-require
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Postmodern
|
7
|
+
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-23 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,9 +20,9 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 1.8.
|
23
|
+
version: 1.8.2
|
24
24
|
version:
|
25
|
-
description: "reverse_require
|
25
|
+
description: "reverse_require will require all files ending with a specified path from within previously installed RubyGems. By using reverse_require in your code-base, it allows developers to extend the functionality of your code-base, by merely adding specially named files to their own RubyGems. Simply use reverse_require in the code-base that you'd like to be extendable: reverse_require 'some/path' The <tt>some/path.rb</tt> files within the <tt>lib/</tt> directories of other RubyGems will then be loaded. This functionality makes designing plug-in systems ontop of RubyGems trivial."
|
26
26
|
email:
|
27
27
|
- postmodern.mod3@gmail.com
|
28
28
|
executables: []
|
@@ -33,17 +33,19 @@ extra_rdoc_files:
|
|
33
33
|
- History.txt
|
34
34
|
- Manifest.txt
|
35
35
|
- README.txt
|
36
|
+
- TODO.txt
|
36
37
|
files:
|
37
38
|
- History.txt
|
38
39
|
- Manifest.txt
|
39
40
|
- README.txt
|
41
|
+
- TODO.txt
|
40
42
|
- Rakefile
|
41
43
|
- lib/reverse_require.rb
|
42
44
|
- lib/reverse_require/version.rb
|
45
|
+
- lib/reverse_require/exceptions.rb
|
46
|
+
- lib/reverse_require/exceptions/rubygems_version_exception.rb
|
43
47
|
- lib/reverse_require/extensions.rb
|
44
48
|
- lib/reverse_require/extensions/kernel.rb
|
45
|
-
- lib/reverse_require/gems.rb
|
46
|
-
- lib/reverse_require/reverse_require.rb
|
47
49
|
has_rdoc: true
|
48
50
|
homepage: http://reverserequire.rubyforge.org/
|
49
51
|
post_install_message:
|
@@ -67,9 +69,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
69
|
requirements: []
|
68
70
|
|
69
71
|
rubyforge_project: reverserequire
|
70
|
-
rubygems_version: 1.3.
|
72
|
+
rubygems_version: 1.3.1
|
71
73
|
signing_key:
|
72
74
|
specification_version: 2
|
73
|
-
summary: reverse_require
|
75
|
+
summary: reverse_require will require all files ending with a specified path from within previously installed RubyGems
|
74
76
|
test_files: []
|
75
77
|
|
data/lib/reverse_require/gems.rb
DELETED
@@ -1,147 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
|
3
|
-
module ReverseRequire
|
4
|
-
class Gems
|
5
|
-
|
6
|
-
# Paths of the gems
|
7
|
-
attr_reader :paths
|
8
|
-
|
9
|
-
# Gem specifications
|
10
|
-
attr_reader :gem_specs
|
11
|
-
|
12
|
-
#
|
13
|
-
# Creates a new empty Gems object.
|
14
|
-
#
|
15
|
-
def initialize
|
16
|
-
@paths = []
|
17
|
-
@gem_specs = []
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
# Creates a new Gems object containing the gems which depend upon
|
22
|
-
# the RubyGem of the specified _name_.
|
23
|
-
#
|
24
|
-
def Gems.depending_on(name)
|
25
|
-
name = name.to_s
|
26
|
-
spec_dir = File.join(Gem.dir,'specifications')
|
27
|
-
gems = Gems.new
|
28
|
-
|
29
|
-
Gem::SourceIndex.from_installed_gems(spec_dir).each do |path,gem_spec|
|
30
|
-
deps = gem_spec.dependencies.map { |dep| dep.name }
|
31
|
-
|
32
|
-
if deps.include?(name)
|
33
|
-
gem_path = File.expand_path(File.join(Gem.dir,'gems',path))
|
34
|
-
|
35
|
-
gems.enqueue(gem_path,gem_spec)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
return gems
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Returns the number of paths and gem specs.
|
44
|
-
#
|
45
|
-
def length
|
46
|
-
return 0 if (@paths.empty? || @gem_specs.empty?)
|
47
|
-
return [@paths.length, @gem_specs.length].min
|
48
|
-
end
|
49
|
-
|
50
|
-
#
|
51
|
-
# Returns the gem spec with the specified gem _path_.
|
52
|
-
#
|
53
|
-
def [](path)
|
54
|
-
@gem_specs[@paths.index(path)]
|
55
|
-
end
|
56
|
-
|
57
|
-
#
|
58
|
-
# Adds the specified _gem_spec_ with the specified gem _path_.
|
59
|
-
#
|
60
|
-
def []=(path,gem_spec)
|
61
|
-
if @paths.include?(path)
|
62
|
-
@gem_specs[@paths.index(path)] = gem_spec
|
63
|
-
else
|
64
|
-
@paths << path
|
65
|
-
@gem_specs << gem_spec
|
66
|
-
end
|
67
|
-
|
68
|
-
return gem_spec
|
69
|
-
end
|
70
|
-
|
71
|
-
#
|
72
|
-
# Enqueues the specified _gem_spec_ with the specified gem _path_.
|
73
|
-
#
|
74
|
-
def enqueue(path,gem_spec)
|
75
|
-
if @paths.include?(path)
|
76
|
-
@gem_specs[@paths.index(path)] = gem_spec
|
77
|
-
else
|
78
|
-
@paths.unshift(path)
|
79
|
-
@gem_specs.unshift(gem_spec)
|
80
|
-
end
|
81
|
-
|
82
|
-
return self
|
83
|
-
end
|
84
|
-
|
85
|
-
#
|
86
|
-
# Iterates over each path and gem spec, passing each to the given
|
87
|
-
# _block_.
|
88
|
-
#
|
89
|
-
def each(&block)
|
90
|
-
length.times do |i|
|
91
|
-
block.call(@paths[i], @gem_specs[i])
|
92
|
-
end
|
93
|
-
|
94
|
-
return self
|
95
|
-
end
|
96
|
-
|
97
|
-
#
|
98
|
-
# Returns a new Gems object containing the names and paths from the
|
99
|
-
# gems which match the specified _block_.
|
100
|
-
#
|
101
|
-
def select(&block)
|
102
|
-
gems = self.class.new
|
103
|
-
|
104
|
-
each do |path,gem_spec|
|
105
|
-
if block.call(path,gem_spec)
|
106
|
-
gems[path] = gem_spec
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
return gems
|
111
|
-
end
|
112
|
-
|
113
|
-
#
|
114
|
-
# Invokes the given _block_ once for each name and path of the gems.
|
115
|
-
# Returns an +Array+ containing the values returned by the _block_.
|
116
|
-
# If no _block_ is given, an empty +Array+ will be returned.
|
117
|
-
#
|
118
|
-
def map(&block)
|
119
|
-
mapped = []
|
120
|
-
|
121
|
-
each do |path,gem_spec|
|
122
|
-
if block
|
123
|
-
mapped << block.call(path,gem_spec)
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
return mapped
|
128
|
-
end
|
129
|
-
|
130
|
-
#
|
131
|
-
# Returns a new Gems object containing the gems which contain the
|
132
|
-
# specified _sub_path_.
|
133
|
-
#
|
134
|
-
# gems.with_path('some/path') # => {...}
|
135
|
-
#
|
136
|
-
def with_path(sub_path)
|
137
|
-
if File.extname(sub_path).empty?
|
138
|
-
sub_path += '.rb'
|
139
|
-
end
|
140
|
-
|
141
|
-
return select do |path,gem_spec|
|
142
|
-
File.exists?(File.expand_path(File.join(path,sub_path)))
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
end
|
147
|
-
end
|
@@ -1,38 +0,0 @@
|
|
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
|
-
activated = Gem.loaded_specs.any? do |active_path,activated_spec|
|
22
|
-
activated_spec.name == gem_spec.name &&
|
23
|
-
activated_spec.version != gem_spec.version
|
24
|
-
end
|
25
|
-
|
26
|
-
unless activated
|
27
|
-
begin
|
28
|
-
gem(gem_spec.name,gem_spec.version)
|
29
|
-
require File.expand_path(File.join(path,lib_path))
|
30
|
-
rescue Gem::Exception
|
31
|
-
next
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
return was_loaded.include?(true)
|
37
|
-
end
|
38
|
-
end
|