drewolson-need 1.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 +25 -0
- data/Manifest.txt +10 -0
- data/Rakefile +18 -0
- data/lib/need.rb +27 -0
- data/test/test_files/file_a.rb +1 -0
- data/test/test_files/file_b.rb +1 -0
- data/test/test_files/file_c.rb +1 -0
- data/test/test_files/require_file.rb +3 -0
- data/test/test_need.rb +20 -0
- metadata +73 -0
data/History.txt
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
|
|
7
|
+
=== 1.0.3 / 2008-05-23
|
|
8
|
+
|
|
9
|
+
* 1 minor enhancement
|
|
10
|
+
* removed unnecessary call to binding on block
|
|
11
|
+
|
|
12
|
+
=== 1.0.2 / 2008-03-18
|
|
13
|
+
|
|
14
|
+
* 1 minor enhancement
|
|
15
|
+
* path creation now uses File.expand_path after joining to give the absolute path
|
|
16
|
+
|
|
17
|
+
=== 1.0.1 / 2008-02-07
|
|
18
|
+
|
|
19
|
+
* 1 minor enhancement
|
|
20
|
+
* path creation now uses File.join to remain platform agnostic
|
|
21
|
+
|
|
22
|
+
=== 1.0.0 / 2008-02-07
|
|
23
|
+
|
|
24
|
+
* 1 major enhancement
|
|
25
|
+
* need can require files relative to the file in which you are calling need.
|
data/Manifest.txt
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
|
|
3
|
+
require 'rubygems'
|
|
4
|
+
require 'hoe'
|
|
5
|
+
require './lib/need.rb'
|
|
6
|
+
|
|
7
|
+
Hoe.new('need', Need::VERSION) do |p|
|
|
8
|
+
p.rubyforge_name = 'need'
|
|
9
|
+
p.author = 'Drew Olson'
|
|
10
|
+
p.email = 'drew@drewolson.org'
|
|
11
|
+
p.summary = 'Need makes relative requries just work'
|
|
12
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
|
13
|
+
p.url = "http://need.rubyforge.org"
|
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
|
15
|
+
p.remote_rdoc_dir = ''
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# vim: syntax=Ruby
|
data/lib/need.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Need
|
|
2
|
+
VERSION = '1.1.0'
|
|
3
|
+
|
|
4
|
+
# need takes a block which should contain a string of the relative path to the file
|
|
5
|
+
# you wish to need.
|
|
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
|
|
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
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
class Object
|
|
26
|
+
include Need
|
|
27
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
need{"require_file"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
need "require_file"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "require_file"
|
data/test/test_need.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "test/unit"
|
|
2
|
+
require "need"
|
|
3
|
+
|
|
4
|
+
class TestNeed < Test::Unit::TestCase
|
|
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
|
+
|
|
10
|
+
def test_need_with_argument
|
|
11
|
+
need "test_files/file_b"
|
|
12
|
+
assert file_loaded?, "require_file was not needed correctly"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_require
|
|
16
|
+
assert_raise LoadError do
|
|
17
|
+
require "test_files/file_c"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: drewolson-need
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Drew Olson
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-12-02 00:00:00 -08:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: hoe
|
|
17
|
+
version_requirement:
|
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.8.2
|
|
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\"} need \"extensions/file_b\""
|
|
25
|
+
email: drew@drewolson.org
|
|
26
|
+
executables: []
|
|
27
|
+
|
|
28
|
+
extensions: []
|
|
29
|
+
|
|
30
|
+
extra_rdoc_files:
|
|
31
|
+
- History.txt
|
|
32
|
+
- Manifest.txt
|
|
33
|
+
- README.txt
|
|
34
|
+
files:
|
|
35
|
+
- History.txt
|
|
36
|
+
- Manifest.txt
|
|
37
|
+
- README.txt
|
|
38
|
+
- Rakefile
|
|
39
|
+
- lib/need.rb
|
|
40
|
+
- test/test_files/file_a.rb
|
|
41
|
+
- test/test_files/file_b.rb
|
|
42
|
+
- test/test_files/file_c.rb
|
|
43
|
+
- test/test_files/require_file.rb
|
|
44
|
+
- test/test_need.rb
|
|
45
|
+
has_rdoc: true
|
|
46
|
+
homepage: http://need.rubyforge.org
|
|
47
|
+
post_install_message:
|
|
48
|
+
rdoc_options:
|
|
49
|
+
- --main
|
|
50
|
+
- README.txt
|
|
51
|
+
require_paths:
|
|
52
|
+
- lib
|
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: "0"
|
|
58
|
+
version:
|
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: "0"
|
|
64
|
+
version:
|
|
65
|
+
requirements: []
|
|
66
|
+
|
|
67
|
+
rubyforge_project: need
|
|
68
|
+
rubygems_version: 1.2.0
|
|
69
|
+
signing_key:
|
|
70
|
+
specification_version: 2
|
|
71
|
+
summary: Need makes relative requries just work
|
|
72
|
+
test_files:
|
|
73
|
+
- test/test_need.rb
|