simonmenke-need 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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.
@@ -0,0 +1,10 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/need.rb
6
+ test/test_files/file_a.rb
7
+ test/test_files/file_b.rb
8
+ test/test_files/file_c.rb
9
+ test/test_files/require_file.rb
10
+ test/test_need.rb
@@ -0,0 +1,60 @@
1
+ = need
2
+
3
+ * http://need.rubyforge.org
4
+ * source code - http://github.com/dfg59/need/tree/master
5
+
6
+ == DESCRIPTION:
7
+
8
+ Need makes ruby relative requires just work. Simply need a file with a relative path
9
+ and the file will always be required correctly, regardless of what file your application is
10
+ being launched through. Typically, ruby projects would unshift lib onto $PATH or use the
11
+ File.dirname(__FILE__) trick. Using need means you don't have to worry about either of these.
12
+
13
+ Assume you have two files, one directly in lib and the other in lib/extensions. Let's assume
14
+ that file_a in lib requires file_b, in lib/extensions. Previously, you would doing some crazy
15
+ load path unshifting or use the __FILE__ trick to make these requires flexible enough to work
16
+ when your app is being accessed by rake, through a test suite, or required as a gem. Now, just
17
+ use need.
18
+
19
+ In file_a:
20
+ need{"extensions/file_b"}
21
+ need "extensions/file_b"
22
+
23
+ == FEATURES/PROBLEMS:
24
+
25
+ == SYNOPSIS:
26
+
27
+ need{"relative/path/to/file"}
28
+ need "relative/path/to/file"
29
+
30
+ == REQUIREMENTS:
31
+
32
+ == INSTALL:
33
+
34
+ * rubyforge - sudo gem install need
35
+ * github - sudo gem install dfg59-need --source=http://gems.github.com
36
+
37
+ == LICENSE:
38
+
39
+ (The MIT License)
40
+
41
+ Copyright (c) 2008 FIX
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ 'Software'), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
57
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
58
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
59
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
60
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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
@@ -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"
@@ -0,0 +1,3 @@
1
+ def file_loaded?
2
+ true
3
+ end
@@ -0,0 +1,18 @@
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
+ 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
17
+ end
18
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simonmenke-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-05-24 00:00:00 -07: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.5.3
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.0.1
69
+ signing_key:
70
+ specification_version: 2
71
+ summary: Need makes relative requries just work
72
+ test_files:
73
+ - test/test_need.rb