require_relative 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -4,7 +4,7 @@
4
4
  # development environment upon cd'ing into the directory
5
5
 
6
6
  # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
- environment_id="ruby-1.8.7-p330@require_relative"
7
+ environment_id="ruby-1.8.7@require_relative"
8
8
 
9
9
  #
10
10
  # First we attempt to load the desired environment directly from the environment
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ require_relative
2
+ ================
3
+
4
+ In Ruby 1.9.2, "." was removed from the $LOAD_PATH. require_relative was
5
+ added to let you require files relative to your current directory.
6
+
7
+ This gem backports both of these features to earlier Rubies.
8
+
9
+ ## Usage
10
+
11
+ require 'rubygems'
12
+ require 'require_relative'
13
+
14
+ require 'foo' #=> LoadError
15
+ require_relative 'foo' #=> works!
@@ -1,8 +1,7 @@
1
- $:.delete(".")
2
-
3
- def require_relative file
4
- $:.unshift(".")
5
- ret = require file
6
- $:.delete(".")
7
- ret
1
+ def require_relative(relative_feature)
2
+ file = caller.first.split(/:\d/,2).first
3
+ if /\A\((.*)\)/ =~ file # eval, etc.
4
+ raise LoadError, "require_relative is called in #{$1}"
5
+ end
6
+ require File.expand_path(relative_feature, File.dirname(file))
8
7
  end
@@ -1,3 +1,3 @@
1
1
  module RequireRelative
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -5,14 +5,22 @@ require 'minitest/autorun'
5
5
  require 'require_relative'
6
6
 
7
7
  class RequireRelativeTest < MiniTest::Unit::TestCase
8
+ # after each test we reset Ruby's internal list of required files, so that we
9
+ # can rerequire the ones we're testing with
10
+ def setup
11
+ @req_length = $".length
12
+ end
8
13
 
9
- def test_current_dir_not_in_load_path
10
- assert_nil $:.detect{|i| i == "."}
14
+ def teardown
15
+ $".pop($".length - @req_length)
11
16
  end
12
17
 
13
18
  def test_require_relative
14
- assert require_relative('test/foo')
19
+ assert require_relative('foo')
15
20
  end
16
21
 
22
+ def test_require_relative_subdir
23
+ assert require_relative('subdir/bar')
24
+ end
17
25
  end
18
26
 
@@ -0,0 +1 @@
1
+ require_relative '../foo'
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: require_relative
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
5
+ version: 0.0.3
11
6
  platform: ruby
12
7
  authors:
13
8
  - Steve Klabnik
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-03-05 00:00:00 -05:00
13
+ date: 2011-03-31 00:00:00 -04:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,9 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
24
  version: "0"
33
25
  type: :development
34
26
  version_requirements: *id001
@@ -45,12 +37,14 @@ files:
45
37
  - .gitignore
46
38
  - .rvmrc
47
39
  - Gemfile
40
+ - README.md
48
41
  - Rakefile
49
42
  - lib/require_relative.rb
50
43
  - lib/require_relative/version.rb
51
44
  - require_relative.gemspec
52
45
  - test/foo.rb
53
46
  - test/require_relative_test.rb
47
+ - test/subdir/bar.rb
54
48
  has_rdoc: true
55
49
  homepage: ""
56
50
  licenses: []
@@ -65,26 +59,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
59
  requirements:
66
60
  - - ">="
67
61
  - !ruby/object:Gem::Version
68
- hash: 3
69
- segments:
70
- - 0
71
62
  version: "0"
72
63
  required_rubygems_version: !ruby/object:Gem::Requirement
73
64
  none: false
74
65
  requirements:
75
66
  - - ">="
76
67
  - !ruby/object:Gem::Version
77
- hash: 3
78
- segments:
79
- - 0
80
68
  version: "0"
81
69
  requirements: []
82
70
 
83
71
  rubyforge_project:
84
- rubygems_version: 1.5.0
72
+ rubygems_version: 1.6.2
85
73
  signing_key:
86
74
  specification_version: 3
87
75
  summary: This backports require_relative to Ruby 1.8.
88
76
  test_files:
89
77
  - test/foo.rb
90
78
  - test/require_relative_test.rb
79
+ - test/subdir/bar.rb