reverse-require 0.2.0 → 0.3.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 +9 -0
- data/Manifest.txt +2 -2
- data/README.txt +24 -13
- data/lib/reverse_require.rb +5 -1
- data/lib/reverse_require/extensions.rb +1 -0
- data/lib/reverse_require/extensions/kernel.rb +28 -16
- data/lib/reverse_require/extensions/rubygems.rb +46 -0
- data/lib/reverse_require/reverse_require.rb +15 -0
- data/lib/reverse_require/version.rb +1 -1
- metadata +6 -6
- data/lib/reverse_require/exceptions.rb +0 -1
- data/lib/reverse_require/exceptions/rubygems_version_exception.rb +0 -4
data/History.txt
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
=== 0.3.0 / 2009-01-08
|
2
|
+
|
3
|
+
* Added Kernel#require_for.
|
4
|
+
* Changed how Kernel#reverse_require behaves.
|
5
|
+
* Changed how Kernel#require_all behaves.
|
6
|
+
* Added extensions to the Gem module:
|
7
|
+
* Gem.find_resources
|
8
|
+
* Gem.find_resources_for
|
9
|
+
|
1
10
|
=== 0.2.0 / 2008-11-23
|
2
11
|
|
3
12
|
* Use the new Gem.find_files method provided by RubyGems >= 1.3.0. Using
|
data/Manifest.txt
CHANGED
@@ -5,7 +5,7 @@ TODO.txt
|
|
5
5
|
Rakefile
|
6
6
|
lib/reverse_require.rb
|
7
7
|
lib/reverse_require/version.rb
|
8
|
-
lib/reverse_require/exceptions.rb
|
9
|
-
lib/reverse_require/exceptions/rubygems_version_exception.rb
|
10
8
|
lib/reverse_require/extensions.rb
|
9
|
+
lib/reverse_require/extensions/rubygems.rb
|
11
10
|
lib/reverse_require/extensions/kernel.rb
|
11
|
+
lib/reverse_require/reverse_require.rb
|
data/README.txt
CHANGED
@@ -1,30 +1,41 @@
|
|
1
1
|
= ReverseRequire
|
2
2
|
|
3
3
|
* http://reverserequire.rubyforge.org/
|
4
|
+
* http://github.com/postmodern/reverse-require
|
4
5
|
* Postmodern (postmodern.mod3 at gmail.com)
|
5
6
|
|
6
7
|
== DESCRIPTION:
|
7
8
|
|
8
|
-
|
9
|
-
|
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:
|
9
|
+
reverse-require allows one to require files that ends with a specified path
|
10
|
+
from other RubyGems.
|
13
11
|
|
14
|
-
|
12
|
+
For instance, if one wanted to require the file 'mylibrary/extensions.rb'
|
13
|
+
from all RubyGems:
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
require 'reverse_require'
|
16
|
+
|
17
|
+
require_all 'mylibrary/extensions'
|
18
|
+
# => true
|
19
|
+
|
20
|
+
One can also require 'mylibrary/extensions.rb' only from RubyGems that
|
21
|
+
depend on the currently loaded version of the mylibrary Gem:
|
22
|
+
|
23
|
+
require_for 'mylibrary', 'mylibrary/extensions'
|
24
|
+
# => true
|
19
25
|
|
20
26
|
== FEATURES/PROBLEMS:
|
21
27
|
|
22
|
-
* Require files ending with a specified path from
|
23
|
-
|
28
|
+
* Require files ending with a specified path from all RubyGems.
|
29
|
+
* Require files ending with a specified path from RubyGems that depends on
|
30
|
+
another specified RubyGem.
|
31
|
+
* Provides extensions to RubyGems for finding static resources in other
|
32
|
+
RubyGems:
|
33
|
+
* Gem.find_resources
|
34
|
+
* Gem.find_resources_for
|
24
35
|
|
25
36
|
== REQUIREMENTS:
|
26
37
|
|
27
|
-
*
|
38
|
+
* rubygems >= 1.3.0
|
28
39
|
|
29
40
|
== INSTALL:
|
30
41
|
|
@@ -34,7 +45,7 @@ plug-in systems ontop of RubyGems trivial.
|
|
34
45
|
|
35
46
|
The MIT License
|
36
47
|
|
37
|
-
Copyright (c) 2008 Hal Brodigan
|
48
|
+
Copyright (c) 2008-2009 Hal Brodigan
|
38
49
|
|
39
50
|
Permission is hereby granted, free of charge, to any person obtaining
|
40
51
|
a copy of this software and associated documentation files (the
|
data/lib/reverse_require.rb
CHANGED
@@ -1,24 +1,14 @@
|
|
1
|
-
require 'reverse_require/
|
1
|
+
require 'reverse_require/extensions/rubygems'
|
2
2
|
|
3
3
|
module Kernel
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
# specified _path_, +false+ will be returned.
|
5
|
+
# Require the given _paths_ in reverse. Returns +false+ if all of the
|
6
|
+
# paths are already loaded, returns +true+ otherwise.
|
8
7
|
#
|
9
|
-
|
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
|
-
|
8
|
+
def reverse_require(*paths)
|
19
9
|
was_loaded = false
|
20
10
|
|
21
|
-
|
11
|
+
paths.reverse_each do |path|
|
22
12
|
begin
|
23
13
|
if File.file?(path)
|
24
14
|
was_loaded ||= require path
|
@@ -31,5 +21,27 @@ module Kernel
|
|
31
21
|
return was_loaded
|
32
22
|
end
|
33
23
|
|
34
|
-
|
24
|
+
#
|
25
|
+
# Requires files from previously installed RubyGems that also end with
|
26
|
+
# the specified _path_. Returns +false+ if no RubyGem contains the
|
27
|
+
# specified _path_, returns +true+ otherwise.
|
28
|
+
#
|
29
|
+
# require_all 'ronin/models'
|
30
|
+
# # => true
|
31
|
+
#
|
32
|
+
def require_all(path)
|
33
|
+
reverse_require(*Gem.find_files(path))
|
34
|
+
end
|
35
|
+
|
36
|
+
#
|
37
|
+
# Requires files that end with the specified _path_, from previously
|
38
|
+
# installed RubyGems which depend on the specified _gem_. Returns +false+
|
39
|
+
# if no RubyGem contains the specified _path_, returns +true+ otherwise.
|
40
|
+
#
|
41
|
+
# require_for 'ronin', 'ronin/models'
|
42
|
+
# # => true
|
43
|
+
#
|
44
|
+
def require_for(gem,path)
|
45
|
+
reverse_require(*Gem.find_files_for(gem,path))
|
46
|
+
end
|
35
47
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
module Gem
|
4
|
+
#
|
5
|
+
# Find all files that end with the specified _path_, from within RubyGems
|
6
|
+
# that depend on the specified _gem_.
|
7
|
+
#
|
8
|
+
def self.find_files_for(gem,path)
|
9
|
+
if (spec = Gem.loaded_specs[gem])
|
10
|
+
version = spec.version
|
11
|
+
else
|
12
|
+
version = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
dep = Gem.source_index.find_name(gem,version).first
|
16
|
+
|
17
|
+
dep.dependent_gems.map { |deps|
|
18
|
+
Gem.searcher.matching_files deps.first, path
|
19
|
+
}.flatten
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Find resources that end with the specified _path_ from all RubyGems.
|
24
|
+
#
|
25
|
+
# Gem.find_resources 'static/template.erb'
|
26
|
+
# # => [...]
|
27
|
+
#
|
28
|
+
def self.find_resources(path)
|
29
|
+
find_files(File.join('..',path)).map do |gem_path|
|
30
|
+
File.expand_path(gem_path)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
#
|
35
|
+
# Find resources that end with the specified _path_, from within RubyGems
|
36
|
+
# that depend on the specified _gem_.
|
37
|
+
#
|
38
|
+
# Gem.find_resources_for 'statix', 'static/xsl/page.xsl'
|
39
|
+
# # => [...]
|
40
|
+
#
|
41
|
+
def self.find_resources_for(gem,path)
|
42
|
+
find_files_for(gem,File.join('..',path)).map do |gem_path|
|
43
|
+
File.expand_path(gem_path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ReverseRequire
|
2
|
+
#
|
3
|
+
# Preforms a version check on rubygems before calling the given _block_.
|
4
|
+
# If rubygems >= 1.3.0 is not found, then an exception will be raised.
|
5
|
+
#
|
6
|
+
def self.rubygems_version_check(&block)
|
7
|
+
major, minor, rev = Gem::RubyGemsVersion.split('.').map { |i| i.to_i }
|
8
|
+
|
9
|
+
if (major <= 1 && minor <= 2)
|
10
|
+
raise("rubygems >= 1.3.0 is required, please run 'gem update --system'")
|
11
|
+
end
|
12
|
+
|
13
|
+
block.call if block
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reverse-require
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-08 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: 1.8.2
|
24
24
|
version:
|
25
|
-
description: "
|
25
|
+
description: "reverse-require allows one to require files that ends with a specified path from other RubyGems. For instance, if one wanted to require the file 'mylibrary/extensions.rb' from all RubyGems: require 'reverse_require' require_all 'mylibrary/extensions' # => true One can also require 'mylibrary/extensions.rb' only from RubyGems that depend on the currently loaded version of the mylibrary Gem: require_for 'mylibrary', 'mylibrary/extensions' # => true"
|
26
26
|
email:
|
27
27
|
- postmodern.mod3@gmail.com
|
28
28
|
executables: []
|
@@ -42,10 +42,10 @@ files:
|
|
42
42
|
- Rakefile
|
43
43
|
- lib/reverse_require.rb
|
44
44
|
- lib/reverse_require/version.rb
|
45
|
-
- lib/reverse_require/exceptions.rb
|
46
|
-
- lib/reverse_require/exceptions/rubygems_version_exception.rb
|
47
45
|
- lib/reverse_require/extensions.rb
|
46
|
+
- lib/reverse_require/extensions/rubygems.rb
|
48
47
|
- lib/reverse_require/extensions/kernel.rb
|
48
|
+
- lib/reverse_require/reverse_require.rb
|
49
49
|
has_rdoc: true
|
50
50
|
homepage: http://reverserequire.rubyforge.org/
|
51
51
|
post_install_message:
|
@@ -72,6 +72,6 @@ rubyforge_project: reverserequire
|
|
72
72
|
rubygems_version: 1.3.1
|
73
73
|
signing_key:
|
74
74
|
specification_version: 2
|
75
|
-
summary:
|
75
|
+
summary: reverse-require allows one to require files that ends with a specified path from other RubyGems
|
76
76
|
test_files: []
|
77
77
|
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'reverse_require/exceptions/rubygems_version_exception'
|