rbx-require-relative 0.0.4-universal-rubinius-1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +75 -0
- data/LICENSE +23 -0
- data/NEWS +13 -0
- data/README.textile +13 -0
- data/Rakefile +108 -0
- data/lib/require_relative.rb +60 -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 +104 -0
data/ChangeLog
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
2010-09-23 rocky <rockyb@rubyforge.org>
|
2
|
+
|
3
|
+
* .gemspec: Need symbol in defined?
|
4
|
+
|
5
|
+
2010-09-23 rocky <rockyb@rubyforge.org>
|
6
|
+
|
7
|
+
* .gemspec, Rakefile, lib/version.rb: Rakefile: check to see if
|
8
|
+
require_relative is already installed. .gemspec: cut-n-paste error
|
9
|
+
version.rb: bump version #
|
10
|
+
|
11
|
+
2010-09-22 rocky <rockyb@rubyforge.org>
|
12
|
+
|
13
|
+
* .gemspec: Bang on gemspec Ruby version. For rubinius 1.0.1 .. 1.1
|
14
|
+
Gem.ruby_version is 1.8.7. I'm imagining 1.9 features will report
|
15
|
+
1.9 or some such thing.
|
16
|
+
|
17
|
+
2010-09-22 rocky <rockyb@rubyforge.org>
|
18
|
+
|
19
|
+
* .gemspec, NEWS, lib/version.rb: Update gemspec homepage link
|
20
|
+
|
21
|
+
2010-09-22 rocky <rockyb@rubyforge.org>
|
22
|
+
|
23
|
+
* README.textile: More README tweaking
|
24
|
+
|
25
|
+
2010-09-22 rocky <rockyb@rubyforge.org>
|
26
|
+
|
27
|
+
* README.textile: More README tweaking
|
28
|
+
|
29
|
+
2010-09-22 rocky <rockyb@rubyforge.org>
|
30
|
+
|
31
|
+
* README.textile: textile hacking.
|
32
|
+
|
33
|
+
2010-09-22 rocky <rockyb@rubyforge.org>
|
34
|
+
|
35
|
+
* .gemspec, README.textile: Get version ranges in correctly.
|
36
|
+
|
37
|
+
2010-09-22 rocky <rockyb@rubyforge.org>
|
38
|
+
|
39
|
+
* .gemspec, ChangeLog, Makefile, NEWS, README.textile, Rakefile,
|
40
|
+
lib/Makefile, test/test-rr.rb: Get ready for release.
|
41
|
+
|
42
|
+
2010-09-20 rocky <rockyb@rubyforge.org>
|
43
|
+
|
44
|
+
* lib/version.rb: Set version number back to what it was
|
45
|
+
|
46
|
+
2010-09-20 rocky <rockyb@rubyforge.org>
|
47
|
+
|
48
|
+
* Rakefile, lib/require_relative.rb, test/test-rr.rb:
|
49
|
+
require_relative: Add RequireRelative::abs_file which is like
|
50
|
+
__FILE__ but gives the absolute location. Rakefile: Had broken
|
51
|
+
tests because rake's default mechanism appears to be broken here and
|
52
|
+
I don't know why. test-rr.rb: Reinstate more stringent testing -
|
53
|
+
chdir before require_relative
|
54
|
+
|
55
|
+
2010-09-20 rocky <rockyb@rubyforge.org>
|
56
|
+
|
57
|
+
* .gemspec, Makefile, Rakefile, lib/.gitignore, lib/Makefile,
|
58
|
+
lib/version.rb: Administrivia: Add packaging, a .gemspec, make
|
59
|
+
comptaibility and so on.
|
60
|
+
|
61
|
+
2010-09-19 rocky <rockyb@rubyforge.org>
|
62
|
+
|
63
|
+
* ChangeLog, Rakefile, lib/require_relative.rb,
|
64
|
+
require_relative.rb, test/test-rr.rb: Gem packaging - this time, for
|
65
|
+
sure!
|
66
|
+
|
67
|
+
2010-09-18 rocky <rockyb@rubyforge.org>
|
68
|
+
|
69
|
+
* .gitignore, ChangeLog, README.textile, Rakefile: Bang on Rakefile
|
70
|
+
for testing packaging and installing.
|
71
|
+
|
72
|
+
2010-09-18 rvm <rocky-rvm@static-71-183-236-17.nycmny.fios.verizon.net>
|
73
|
+
|
74
|
+
* Initial require_relative code.
|
75
|
+
|
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/NEWS
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
0.0.4 (04-22-11)
|
2
|
+
|
3
|
+
- Using an undocumented API has changed in Rubinius 1.2.4dev. Down
|
4
|
+
the line, we need to get an API for RequireRelative#abs_file in
|
5
|
+
Rubinius. Until then, we'll have to change code.
|
6
|
+
|
7
|
+
0.0.3 (09-27-10)
|
8
|
+
|
9
|
+
- Small .gemspec packaging issues
|
10
|
+
|
11
|
+
0.0.2 (09-22-10)
|
12
|
+
|
13
|
+
- First public release.
|
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,108 @@
|
|
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 or 1.9.2-nframe only!' unless
|
5
|
+
(Object.constants.include?('Rubinius') &&
|
6
|
+
Rubinius.constants.include?('VM') &&
|
7
|
+
Rubinius::VM.respond_to?(:backtrace)) ||
|
8
|
+
(defined? RUBY_DESCRIPTION && RUBY_DESCRIPTION.start_with?('ruby 1.9.2frame'))
|
9
|
+
|
10
|
+
# begin
|
11
|
+
# require_relative 'lib/version'
|
12
|
+
# puts 'Looks like you already have require_relative!'
|
13
|
+
# exit 5
|
14
|
+
# rescue NameError
|
15
|
+
# end
|
16
|
+
|
17
|
+
require 'rubygems'
|
18
|
+
require 'rake/gempackagetask'
|
19
|
+
require 'rake/rdoctask'
|
20
|
+
require 'rake/testtask'
|
21
|
+
require 'fileutils'
|
22
|
+
|
23
|
+
ROOT_DIR = File.dirname(__FILE__)
|
24
|
+
require File.join(ROOT_DIR, '/lib/version')
|
25
|
+
|
26
|
+
def gemspec
|
27
|
+
@gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
|
28
|
+
end
|
29
|
+
|
30
|
+
def gem_file
|
31
|
+
"#{gemspec.name}-#{gemspec.version}-#{gemspec.platform.to_s}.gem"
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
desc "Build the gem"
|
36
|
+
task :package=>:gem
|
37
|
+
task :gem=>:gemspec do
|
38
|
+
sh "gem build .gemspec"
|
39
|
+
FileUtils.mkdir_p 'pkg'
|
40
|
+
FileUtils.mv gem_file, 'pkg'
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => [:test]
|
44
|
+
|
45
|
+
desc 'Install locally'
|
46
|
+
task :install => :package do
|
47
|
+
Dir.chdir(ROOT_DIR) do
|
48
|
+
sh %{gem install --local pkg/#{gem_file}}
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Test everything.'
|
53
|
+
Rake::TestTask.new(:test) do |t|
|
54
|
+
t.libs << './lib'
|
55
|
+
t.pattern = 'test/test-*.rb'
|
56
|
+
t.options = '--verbose' if $VERBOSE
|
57
|
+
end
|
58
|
+
task :test => [:lib]
|
59
|
+
|
60
|
+
require 'rbconfig'
|
61
|
+
RUBY_PATH = File.join(RbConfig::CONFIG['bindir'],
|
62
|
+
RbConfig::CONFIG['RUBY_INSTALL_NAME'])
|
63
|
+
|
64
|
+
def run_standalone_ruby_file(directory)
|
65
|
+
# puts ('*' * 10) + ' ' + directory + ' ' + ('*' * 10)
|
66
|
+
Dir.chdir(directory) do
|
67
|
+
Dir.glob('test-rr.rb').each do |ruby_file|
|
68
|
+
# puts( ('-' * 20) + ' ' + ruby_file + ' ' + ('-' * 20))
|
69
|
+
system(RUBY_PATH, ruby_file)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
desc "Run each library Ruby file in standalone mode."
|
76
|
+
rake_dir = File.dirname(__FILE__)
|
77
|
+
task :check do
|
78
|
+
run_standalone_ruby_file(File.join(%W(#{rake_dir} test)))
|
79
|
+
end
|
80
|
+
task :default => [:test]
|
81
|
+
|
82
|
+
# Remove the above when I figure out what's up with the commented-out code.
|
83
|
+
|
84
|
+
desc 'Create a GNU-style ChangeLog via git2cl'
|
85
|
+
task :ChangeLog do
|
86
|
+
system('git log --pretty --numstat --summary | git2cl > ChangeLog')
|
87
|
+
end
|
88
|
+
|
89
|
+
desc "Remove built files"
|
90
|
+
task :clean => [:clobber_package, :clobber_rdoc]
|
91
|
+
|
92
|
+
desc "Generate the gemspec"
|
93
|
+
task :generate do
|
94
|
+
puts gemspec.to_ruby
|
95
|
+
end
|
96
|
+
|
97
|
+
desc "Validate the gemspec"
|
98
|
+
task :gemspec do
|
99
|
+
gemspec.validate
|
100
|
+
end
|
101
|
+
|
102
|
+
task :clobber_package do
|
103
|
+
FileUtils.rm_rf File.join(ROOT_DIR, 'pkg')
|
104
|
+
end
|
105
|
+
|
106
|
+
task :clobber_rdoc do
|
107
|
+
FileUtils.rm_rf File.join(ROOT_DIR, 'doc')
|
108
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Ruby 1.9's require_relative.
|
2
|
+
|
3
|
+
if defined?(RubyVM)
|
4
|
+
require 'thread_frame'
|
5
|
+
end
|
6
|
+
|
7
|
+
module RequireRelative
|
8
|
+
def abs_file
|
9
|
+
if defined?(RubyVM::ThreadFrame)
|
10
|
+
RubyVM::ThreadFrame.current.prev.source_container[1]
|
11
|
+
elsif defined?(Rubinius) && "1.8.7" == RUBY_VERSION
|
12
|
+
scope = Rubinius::StaticScope.of_sender
|
13
|
+
script = scope.current_script
|
14
|
+
if script
|
15
|
+
script.data_path
|
16
|
+
else
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
module_function :abs_file
|
22
|
+
end
|
23
|
+
|
24
|
+
# On platforms other than Rubinius for 1.8.7
|
25
|
+
# don't do anything.
|
26
|
+
if defined?(Rubinius) && "1.8.7" == RUBY_VERSION
|
27
|
+
module Kernel
|
28
|
+
def require_relative(suffix)
|
29
|
+
# Rubinius::Location#file stores relative file names while
|
30
|
+
# Rubinius::Location#scope.current_script.data_path stores the
|
31
|
+
# absolute file name. It is possible (hopeful even) that in the
|
32
|
+
# future that Rubinius will change the API to be more
|
33
|
+
# intuitive. When that occurs, I'll change the below to that
|
34
|
+
# simpler thing.
|
35
|
+
scope = Rubinius::StaticScope.of_sender
|
36
|
+
script = scope.current_script
|
37
|
+
if script
|
38
|
+
require File.join(File.dirname(script.data_path), suffix)
|
39
|
+
else
|
40
|
+
raise LoadError "Something is wrong in trying to get relative path"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# demo
|
47
|
+
if __FILE__ == $0
|
48
|
+
file = RequireRelative.abs_file
|
49
|
+
puts file
|
50
|
+
require 'tmpdir'
|
51
|
+
Dir.chdir(Dir.tmpdir) do
|
52
|
+
rel_file = File.basename(file)
|
53
|
+
cur_dir = File.basename(File.dirname(file))
|
54
|
+
['./', "../#{cur_dir}/"].each do |prefix|
|
55
|
+
test = "#{prefix}#{rel_file}"
|
56
|
+
puts "#{test}: #{require_relative test}"
|
57
|
+
puts "#{test}: #{require_relative test} -- should be false"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
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,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbx-require-relative
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
|
+
platform: universal-rubinius-1.2
|
12
|
+
authors:
|
13
|
+
- R. Bernstein
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-22 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: diff-lcs
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: |
|
36
|
+
Ruby 1.9's require_relative for Rubinius.
|
37
|
+
|
38
|
+
We also add abs_path which is like __FILE__ but __FILE__ can be fooled
|
39
|
+
by a sneaky "chdir" while abs_path can't.
|
40
|
+
|
41
|
+
If you are running on Ruby 1.9.2, require_relative is the pre-defined
|
42
|
+
version. The benefit we provide in this situation by this package is
|
43
|
+
the ability to write the same require_relative sequence in Rubinius
|
44
|
+
1.8 and Ruby 1.9.
|
45
|
+
|
46
|
+
email: rockyb@rubyforge.net
|
47
|
+
executables: []
|
48
|
+
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
extra_rdoc_files: []
|
52
|
+
|
53
|
+
files:
|
54
|
+
- LICENSE
|
55
|
+
- ChangeLog
|
56
|
+
- NEWS
|
57
|
+
- README.textile
|
58
|
+
- Rakefile
|
59
|
+
- lib/version.rb
|
60
|
+
- lib/require_relative.rb
|
61
|
+
- test/test-rr.rb
|
62
|
+
- test/foo.rb
|
63
|
+
- test/bar.rb
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/rocky/rbx-require-relative
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --main
|
71
|
+
- README
|
72
|
+
- --title
|
73
|
+
- require_relative 0.0.4 Documentation
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ~>
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: 57
|
82
|
+
segments:
|
83
|
+
- 1
|
84
|
+
- 8
|
85
|
+
- 7
|
86
|
+
version: 1.8.7
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.5.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Ruby 1.9's require_relative for Rubinius. We also add abs_path which is like __FILE__ but __FILE__ can be fooled by a sneaky "chdir" while abs_path can't. If you are running on Ruby 1.9.2, require_relative is the pre-defined version. The benefit we provide in this situation by this package is the ability to write the same require_relative sequence in Rubinius 1.8 and Ruby 1.9.
|
103
|
+
test_files: []
|
104
|
+
|