rbx-require-relative 0.0.2
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/ChangeLog +34 -0
- data/LICENSE +23 -0
- data/NEWS +3 -0
- data/README.textile +13 -0
- data/Rakefile +95 -0
- data/lib/require_relative.rb +36 -0
- data/lib/version.rb +3 -0
- data/test/bar.rb +3 -0
- data/test/foo.rb +3 -0
- data/test/test-rr.rb +27 -0
- metadata +84 -0
data/ChangeLog
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
2010-09-20 rocky <rockyb@rubyforge.org>
|
|
2
|
+
|
|
3
|
+
* lib/version.rb: Set version number back to what it was
|
|
4
|
+
|
|
5
|
+
2010-09-20 rocky <rockyb@rubyforge.org>
|
|
6
|
+
|
|
7
|
+
* Rakefile, lib/require_relative.rb, test/test-rr.rb:
|
|
8
|
+
require_relative: Add RequireRelative::abs_file which is like
|
|
9
|
+
__FILE__ but gives the absolute location. Rakefile: Had broken
|
|
10
|
+
tests because rake's default mechanism appears to be broken here and
|
|
11
|
+
I don't know why. test-rr.rb: Reinstate more stringent testing -
|
|
12
|
+
chdir before require_relative
|
|
13
|
+
|
|
14
|
+
2010-09-20 rocky <rockyb@rubyforge.org>
|
|
15
|
+
|
|
16
|
+
* .gemspec, Makefile, Rakefile, lib/.gitignore, lib/Makefile,
|
|
17
|
+
lib/version.rb: Administrivia: Add packaging, a .gemspec, make
|
|
18
|
+
comptaibility and so on.
|
|
19
|
+
|
|
20
|
+
2010-09-19 rocky <rockyb@rubyforge.org>
|
|
21
|
+
|
|
22
|
+
* ChangeLog, Rakefile, lib/require_relative.rb,
|
|
23
|
+
require_relative.rb, test/test-rr.rb: Gem packaging - this time, for
|
|
24
|
+
sure!
|
|
25
|
+
|
|
26
|
+
2010-09-18 rocky <rockyb@rubyforge.org>
|
|
27
|
+
|
|
28
|
+
* .gitignore, ChangeLog, README.textile, Rakefile: Bang on Rakefile
|
|
29
|
+
for testing packaging and installing.
|
|
30
|
+
|
|
31
|
+
2010-09-18 rvm <rocky-rvm@static-71-183-236-17.nycmny.fios.verizon.net>
|
|
32
|
+
|
|
33
|
+
* Initial require_relative code.
|
|
34
|
+
|
data/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Copyright (C) 2010 Rocky Bernstein <rockyb@rubyforge.org>
|
|
2
|
+
All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions
|
|
6
|
+
are met:
|
|
7
|
+
1. Redistributions of source code must retain the above copyright
|
|
8
|
+
notice, this list of conditions and the following disclaimer.
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
documentation and/or other materials provided with the distribution.
|
|
12
|
+
*
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
14
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
15
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
16
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
17
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
18
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
19
|
+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
20
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
21
|
+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
22
|
+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
23
|
+
SUCH DAMAGE.
|
data/README.textile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
h2. Ruby 1.9's relative_relative for Rubinus 1.0.1 .. 1.1
|
|
2
|
+
|
|
3
|
+
Here we add in Module RequireRelative method: *require_relative*, and *abs_file*. Example:
|
|
4
|
+
|
|
5
|
+
bc. require 'rubygems'; require 'require_relative'
|
|
6
|
+
require_relative './lib/foo'
|
|
7
|
+
absolute_path = RequireRelative.abs_file
|
|
8
|
+
|
|
9
|
+
But why *abs_file*? Well, recall that ==__FILE__== does not give an absolute path. So if you have chdir'd before using ==__FILE__==, you might not be able to retrieve the full path.
|
|
10
|
+
|
|
11
|
+
The latest version is at "http://github.com/rocky/rbx-require-relative/"://github.com/rocky/rbx-require-relative/
|
|
12
|
+
|
|
13
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
# -*- Ruby -*-
|
|
3
|
+
# Are we rubinius? We'll test by checking the specific function we need.
|
|
4
|
+
raise RuntimeError, 'This package is for rubinius only!' unless
|
|
5
|
+
Object.constants.include?('Rubinius') &&
|
|
6
|
+
Rubinius.constants.include?('VM') &&
|
|
7
|
+
Rubinius::VM.respond_to?(:backtrace)
|
|
8
|
+
|
|
9
|
+
require 'rubygems'
|
|
10
|
+
require 'rake/gempackagetask'
|
|
11
|
+
require 'rake/rdoctask'
|
|
12
|
+
require 'rake/testtask'
|
|
13
|
+
require 'fileutils'
|
|
14
|
+
|
|
15
|
+
ROOT_DIR = File.dirname(__FILE__)
|
|
16
|
+
require File.join(ROOT_DIR, '/lib/version')
|
|
17
|
+
|
|
18
|
+
def gemspec
|
|
19
|
+
@gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
desc "Build the gem"
|
|
23
|
+
task :package=>:gem
|
|
24
|
+
task :gem=>:gemspec do
|
|
25
|
+
sh "gem build .gemspec"
|
|
26
|
+
FileUtils.mkdir_p 'pkg'
|
|
27
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
task :default => [:test]
|
|
31
|
+
|
|
32
|
+
desc 'Install locally'
|
|
33
|
+
task :install => :package do
|
|
34
|
+
Dir.chdir(ROOT_DIR) do
|
|
35
|
+
sh %{gem install --local pkg/#{gemspec.name}-#{gemspec.version}}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
desc 'Test everything.'
|
|
40
|
+
Rake::TestTask.new(:test) do |t|
|
|
41
|
+
t.libs << './lib'
|
|
42
|
+
t.pattern = 'test/test-*.rb'
|
|
43
|
+
t.verbose = true
|
|
44
|
+
end
|
|
45
|
+
task :test => [:lib]
|
|
46
|
+
|
|
47
|
+
require 'rbconfig'
|
|
48
|
+
RUBY_PATH = File.join(RbConfig::CONFIG['bindir'],
|
|
49
|
+
RbConfig::CONFIG['RUBY_INSTALL_NAME'])
|
|
50
|
+
|
|
51
|
+
def run_standalone_ruby_file(directory)
|
|
52
|
+
# puts ('*' * 10) + ' ' + directory + ' ' + ('*' * 10)
|
|
53
|
+
Dir.chdir(directory) do
|
|
54
|
+
Dir.glob('test-rr.rb').each do |ruby_file|
|
|
55
|
+
# puts( ('-' * 20) + ' ' + ruby_file + ' ' + ('-' * 20))
|
|
56
|
+
system(RUBY_PATH, ruby_file)
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
desc "Run each library Ruby file in standalone mode."
|
|
63
|
+
rake_dir = File.dirname(__FILE__)
|
|
64
|
+
task :check do
|
|
65
|
+
run_standalone_ruby_file(File.join(%W(#{rake_dir} test)))
|
|
66
|
+
end
|
|
67
|
+
task :default => [:check]
|
|
68
|
+
|
|
69
|
+
# Remove the above when I figure out what's up with the commented-out code.
|
|
70
|
+
|
|
71
|
+
desc 'Create a GNU-style ChangeLog via git2cl'
|
|
72
|
+
task :ChangeLog do
|
|
73
|
+
system('git log --pretty --numstat --summary | git2cl > ChangeLog')
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
desc "Remove built files"
|
|
77
|
+
task :clean => [:clobber_package, :clobber_rdoc]
|
|
78
|
+
|
|
79
|
+
desc "Generate the gemspec"
|
|
80
|
+
task :generate do
|
|
81
|
+
puts gemspec.to_ruby
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
desc "Validate the gemspec"
|
|
85
|
+
task :gemspec do
|
|
86
|
+
gemspec.validate
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
task :clobber_package do
|
|
90
|
+
FileUtils.rm_rf File.join(ROOT_DIR, 'pkg')
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
task :clobber_rdoc do
|
|
94
|
+
FileUtils.rm_rf File.join(ROOT_DIR, 'doc')
|
|
95
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Ruby 1.9's require_relative.
|
|
2
|
+
module RequireRelative
|
|
3
|
+
def abs_file
|
|
4
|
+
Rubinius::VM.backtrace(1)[0].method.scope.data_path
|
|
5
|
+
end
|
|
6
|
+
module_function :abs_file
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module Kernel
|
|
10
|
+
def require_relative(suffix)
|
|
11
|
+
# Rubinius::Location#file stores relative file names while
|
|
12
|
+
# Rubinius::Location#scope.data store the absolute file name. It
|
|
13
|
+
# is possible (hopeful even) that in the future that Rubinius will
|
|
14
|
+
# change the API to be more intuitive. When that occurs, I'll
|
|
15
|
+
# change the below to that simpler thing.
|
|
16
|
+
dir = File.dirname(Rubinius::VM.backtrace(1)[0].
|
|
17
|
+
method.scope.data_path)
|
|
18
|
+
require File.join(dir, suffix)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# demo
|
|
23
|
+
if __FILE__ == $0
|
|
24
|
+
file = RequireRelative.abs_file
|
|
25
|
+
puts file
|
|
26
|
+
require 'tmpdir'
|
|
27
|
+
Dir.chdir(Dir.tmpdir) do
|
|
28
|
+
rel_file = File.basename(file)
|
|
29
|
+
cur_dir = File.basename(File.dirname(file))
|
|
30
|
+
['./', "../#{cur_dir}/"].each do |prefix|
|
|
31
|
+
test = "#{prefix}#{rel_file}"
|
|
32
|
+
puts "#{test}: #{require_relative test}"
|
|
33
|
+
puts "#{test}: #{require_relative test} -- should be false"
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/version.rb
ADDED
data/test/bar.rb
ADDED
data/test/foo.rb
ADDED
data/test/test-rr.rb
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
|
|
3
|
+
# require_relative the old-fashioned way...
|
|
4
|
+
# Note that it's important there be no chdir before this require.
|
|
5
|
+
file = File.expand_path(File.join(File.dirname(__FILE__),
|
|
6
|
+
'../lib/require_relative'))
|
|
7
|
+
require file
|
|
8
|
+
|
|
9
|
+
class TestRR < Test::Unit::TestCase
|
|
10
|
+
require 'tmpdir'
|
|
11
|
+
def test_basic
|
|
12
|
+
# The chdir is to make things harder.
|
|
13
|
+
abs_file = RequireRelative.abs_file
|
|
14
|
+
Dir.chdir(Dir.tmpdir) do
|
|
15
|
+
cur_dir = File.basename(File.expand_path(File.dirname(abs_file)))
|
|
16
|
+
['./foo', "../#{cur_dir}/bar"].each_with_index do |suffix, i|
|
|
17
|
+
assert_equal(true, require_relative(suffix),
|
|
18
|
+
"check require_relative(#{suffix})")
|
|
19
|
+
# Check that the require_relative worked by checking to see of the
|
|
20
|
+
# class from each file was imported.
|
|
21
|
+
assert_equal(Class, (0 == i ? Foo : Bar).class)
|
|
22
|
+
assert_equal(false, require_relative(suffix),
|
|
23
|
+
"require_relative(#{suffix}) second time should be false")
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rbx-require-relative
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 27
|
|
5
|
+
prerelease: false
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 2
|
|
10
|
+
version: 0.0.2
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- R. Bernstein
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2010-09-22 00:00:00 -04:00
|
|
19
|
+
default_executable:
|
|
20
|
+
dependencies: []
|
|
21
|
+
|
|
22
|
+
description: |
|
|
23
|
+
|
|
24
|
+
Ruby 1.9's require_relative for Rubinius
|
|
25
|
+
|
|
26
|
+
email: rockyb@rubyforge.net
|
|
27
|
+
executables: []
|
|
28
|
+
|
|
29
|
+
extensions: []
|
|
30
|
+
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
|
|
33
|
+
files:
|
|
34
|
+
- LICENSE
|
|
35
|
+
- ChangeLog
|
|
36
|
+
- NEWS
|
|
37
|
+
- README.textile
|
|
38
|
+
- Rakefile
|
|
39
|
+
- lib/version.rb
|
|
40
|
+
- lib/require_relative.rb
|
|
41
|
+
- test/test-rr.rb
|
|
42
|
+
- test/foo.rb
|
|
43
|
+
- test/bar.rb
|
|
44
|
+
has_rdoc: true
|
|
45
|
+
homepage: http://github.com/rocky/rbx-require-relative
|
|
46
|
+
licenses:
|
|
47
|
+
- MIT
|
|
48
|
+
post_install_message:
|
|
49
|
+
rdoc_options:
|
|
50
|
+
- --main
|
|
51
|
+
- README
|
|
52
|
+
- --title
|
|
53
|
+
- require_relative 0.0.2 Documentation
|
|
54
|
+
require_paths:
|
|
55
|
+
- lib
|
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ~>
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
hash: 57
|
|
62
|
+
segments:
|
|
63
|
+
- 1
|
|
64
|
+
- 8
|
|
65
|
+
- 7
|
|
66
|
+
version: 1.8.7
|
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
|
+
none: false
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
hash: 3
|
|
73
|
+
segments:
|
|
74
|
+
- 0
|
|
75
|
+
version: "0"
|
|
76
|
+
requirements: []
|
|
77
|
+
|
|
78
|
+
rubyforge_project:
|
|
79
|
+
rubygems_version: 1.3.6
|
|
80
|
+
signing_key:
|
|
81
|
+
specification_version: 3
|
|
82
|
+
summary: Ruby 1.9's require_relative for Rubinius
|
|
83
|
+
test_files: []
|
|
84
|
+
|