need 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.1.0 / 2008-05-24
2
+
3
+ * 1 major enhancement
4
+ * need can now optionally take a path rather than a block
5
+ * thanks simonmenke
6
+
1
7
  === 1.0.3 / 2008-05-23
2
8
 
3
9
  * 1 minor enhancement
data/Manifest.txt CHANGED
@@ -5,4 +5,6 @@ Rakefile
5
5
  lib/need.rb
6
6
  test/test_files/file_a.rb
7
7
  test/test_files/file_b.rb
8
+ test/test_files/file_c.rb
9
+ test/test_files/require_file.rb
8
10
  test/test_need.rb
data/README.txt CHANGED
@@ -18,15 +18,14 @@ use need.
18
18
 
19
19
  In file_a:
20
20
  need{"extensions/file_b"}
21
-
22
- Note that the block syntax is necessary. Need uses the binding of the block to determine the
23
- location of your file and correctly perform your relative require for you.
21
+ need "extensions/file_b"
24
22
 
25
23
  == FEATURES/PROBLEMS:
26
24
 
27
25
  == SYNOPSIS:
28
26
 
29
27
  need{"relative/path/to/file"}
28
+ need "relative/path/to/file"
30
29
 
31
30
  == REQUIREMENTS:
32
31
 
data/lib/need.rb CHANGED
@@ -1,11 +1,25 @@
1
1
  module Need
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.0'
3
3
 
4
4
  # need takes a block which should contain a string of the relative path to the file
5
5
  # you wish to need.
6
- def need(&block)
7
- require File.expand_path(File.join(File.dirname(eval("__FILE__",block)),block.call))
6
+ def need(file=nil, &block)
7
+ if block_given?
8
+ require File.expand_path(File.join(File.dirname(eval("__FILE__",block)),block.call))
9
+ elsif file
10
+ require File.expand_path(File.join(File.dirname(caller_file(1)),file))
11
+ end
8
12
  end
13
+
14
+ def caller_file(level=0)
15
+ if caller[level]
16
+ File.expand_path(caller[level].split(":").first)
17
+ else
18
+ nil
19
+ end
20
+ end
21
+
22
+ private :caller_file
9
23
  end
10
24
 
11
25
  class Object
@@ -1 +1 @@
1
- need{"file_b"}
1
+ need{"require_file"}
@@ -1,3 +1 @@
1
- def file_b_method?
2
- true
3
- end
1
+ need "require_file"
@@ -0,0 +1 @@
1
+ require "require_file"
@@ -0,0 +1,3 @@
1
+ def file_loaded?
2
+ true
3
+ end
data/test/test_need.rb CHANGED
@@ -1,9 +1,18 @@
1
1
  require "test/unit"
2
2
  require "need"
3
- need {"test_files/file_a"}
4
3
 
5
4
  class TestNeed < Test::Unit::TestCase
6
- def test_need
7
- assert file_b_method?, "file_b was not needed correctly"
5
+ def test_need_with_block
6
+ need {"test_files/file_a"}
7
+ assert file_loaded?, "require_file was not needed correctly"
8
+ end
9
+ def test_need_with_argument
10
+ need "test_files/file_b"
11
+ assert file_loaded?, "require_file was not needed correctly"
12
+ end
13
+ def test_require
14
+ assert_raise LoadError do
15
+ require "test_files/file_c"
16
+ end
8
17
  end
9
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: need
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drew Olson
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-05-23 00:00:00 -05:00
12
+ date: 2008-05-24 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,9 +19,9 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.5.1
22
+ version: 1.5.3
23
23
  version:
24
- description: "== DESCRIPTION: Need makes ruby relative requires just work. Simply need a file with a relative path and the file will always be required correctly, regardless of what file your application is being launched through. Typically, ruby projects would unshift lib onto $PATH or use the File.dirname(__FILE__) trick. Using need means you don't have to worry about either of these. Assume you have two files, one directly in lib and the other in lib/extensions. Let's assume that file_a in lib requires file_b, in lib/extensions. Previously, you would doing some crazy load path unshifting or use the __FILE__ trick to make these requires flexible enough to work when your app is being accessed by rake, through a test suite, or required as a gem. Now, just use need. In file_a: need{\"extensions/file_b\"}"
24
+ description: "== DESCRIPTION: Need makes ruby relative requires just work. Simply need a file with a relative path and the file will always be required correctly, regardless of what file your application is being launched through. Typically, ruby projects would unshift lib onto $PATH or use the File.dirname(__FILE__) trick. Using need means you don't have to worry about either of these. Assume you have two files, one directly in lib and the other in lib/extensions. Let's assume that file_a in lib requires file_b, in lib/extensions. Previously, you would doing some crazy load path unshifting or use the __FILE__ trick to make these requires flexible enough to work when your app is being accessed by rake, through a test suite, or required as a gem. Now, just use need. In file_a: need{\"extensions/file_b\"} need \"extensions/file_b\""
25
25
  email: drew@drewolson.org
26
26
  executables: []
27
27
 
@@ -39,6 +39,8 @@ files:
39
39
  - lib/need.rb
40
40
  - test/test_files/file_a.rb
41
41
  - test/test_files/file_b.rb
42
+ - test/test_files/file_c.rb
43
+ - test/test_files/require_file.rb
42
44
  - test/test_need.rb
43
45
  has_rdoc: true
44
46
  homepage: http://need.rubyforge.org