rbx-require-relative 0.0.5-universal-ruby-1.8.7

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog ADDED
@@ -0,0 +1,113 @@
1
+ 2011-06-11 rocky <rockyb@rubyforge.org>
2
+
3
+ * .gemspec, Rakefile: Package name needs the kind of Ruby in it.
4
+ Sigh
5
+
6
+ 2011-06-11 rocky <rockyb@rubyforge.org>
7
+
8
+ * .gemspec, ChangeLog, NEWS, lib/require_relative.rb: Tolerance for
9
+ unpatched 1.9.2
10
+
11
+ 2011-05-26 rocky <rockyb@rubyforge.org>
12
+
13
+ * .gemspec, Rakefile, lib/version.rb: Package versioning for MRI
14
+ 1.8.7 was wrong.
15
+
16
+ 2011-05-26 rocky <rockyb@rubyforge.org>
17
+
18
+ * .gemspec, README.textile, Rakefile, lib/require_relative.rb,
19
+ lib/version.rb, test/test-rr.rb: Handle MRI 1.8
20
+
21
+ 2011-04-22 rocky <rockyb@rubyforge.org>
22
+
23
+ * NEWS, lib/version.rb: Update for release.
24
+
25
+ 2011-04-22 rocky <rockyb@rubyforge.org>
26
+
27
+ * lib/require_relative.rb: Don't use
28
+ Rubinius::StaticScope#data_path, but mirror the logic for that until
29
+ an API is created that works like RequireRelative#abs_file. Also use
30
+ Rubinius::StaticScope.of_sender rather than backtrace. Thanks to
31
+ Evan Phoenix for advice on all of this.
32
+
33
+ 2011-02-14 rocky <rockyb@rubyforge.org>
34
+
35
+ * .gemspec, ChangeLog, NEWS, Rakefile, lib/require_relative.rb,
36
+ lib/version.rb: Allow this to be build on 1.9.2-nframe as mostly a
37
+ no-op.
38
+
39
+ 2010-09-23 rocky <rockyb@rubyforge.org>
40
+
41
+ * .gemspec: Need symbol in defined?
42
+
43
+ 2010-09-23 rocky <rockyb@rubyforge.org>
44
+
45
+ * .gemspec, Rakefile, lib/version.rb: Rakefile: check to see if
46
+ require_relative is already installed. .gemspec: cut-n-paste error
47
+ version.rb: bump version #
48
+
49
+ 2010-09-22 rocky <rockyb@rubyforge.org>
50
+
51
+ * .gemspec: Bang on gemspec Ruby version. For rubinius 1.0.1 .. 1.1
52
+ Gem.ruby_version is 1.8.7. I'm imagining 1.9 features will report
53
+ 1.9 or some such thing.
54
+
55
+ 2010-09-22 rocky <rockyb@rubyforge.org>
56
+
57
+ * .gemspec, NEWS, lib/version.rb: Update gemspec homepage link
58
+
59
+ 2010-09-22 rocky <rockyb@rubyforge.org>
60
+
61
+ * README.textile: More README tweaking
62
+
63
+ 2010-09-22 rocky <rockyb@rubyforge.org>
64
+
65
+ * README.textile: More README tweaking
66
+
67
+ 2010-09-22 rocky <rockyb@rubyforge.org>
68
+
69
+ * README.textile: textile hacking.
70
+
71
+ 2010-09-22 rocky <rockyb@rubyforge.org>
72
+
73
+ * .gemspec, README.textile: Get version ranges in correctly.
74
+
75
+ 2010-09-22 rocky <rockyb@rubyforge.org>
76
+
77
+ * .gemspec, ChangeLog, Makefile, NEWS, README.textile, Rakefile,
78
+ lib/Makefile, test/test-rr.rb: Get ready for release.
79
+
80
+ 2010-09-20 rocky <rockyb@rubyforge.org>
81
+
82
+ * lib/version.rb: Set version number back to what it was
83
+
84
+ 2010-09-20 rocky <rockyb@rubyforge.org>
85
+
86
+ * Rakefile, lib/require_relative.rb, test/test-rr.rb:
87
+ require_relative: Add RequireRelative::abs_file which is like
88
+ __FILE__ but gives the absolute location. Rakefile: Had broken
89
+ tests because rake's default mechanism appears to be broken here and
90
+ I don't know why. test-rr.rb: Reinstate more stringent testing -
91
+ chdir before require_relative
92
+
93
+ 2010-09-20 rocky <rockyb@rubyforge.org>
94
+
95
+ * .gemspec, Makefile, Rakefile, lib/.gitignore, lib/Makefile,
96
+ lib/version.rb: Administrivia: Add packaging, a .gemspec, make
97
+ comptaibility and so on.
98
+
99
+ 2010-09-19 rocky <rockyb@rubyforge.org>
100
+
101
+ * ChangeLog, Rakefile, lib/require_relative.rb,
102
+ require_relative.rb, test/test-rr.rb: Gem packaging - this time, for
103
+ sure!
104
+
105
+ 2010-09-18 rocky <rockyb@rubyforge.org>
106
+
107
+ * .gitignore, ChangeLog, README.textile, Rakefile: Bang on Rakefile
108
+ for testing packaging and installing.
109
+
110
+ 2010-09-18 rvm <rocky-rvm@static-71-183-236-17.nycmny.fios.verizon.net>
111
+
112
+ * Initial require_relative code.
113
+
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,23 @@
1
+ 0.0.5 (06-12-11) Fleetwood release
2
+
3
+ Allow this to work on Ruby MRI 1.8 and 1.9. On 1.9 we don't do
4
+ anything for require_relative, but in 1.9.2+thread_frame we add a
5
+ relible abs_path. This package is provided on 1.9 is there for
6
+ compatibility and for abs_path for a threadframe-enabled 1.9.2.
7
+
8
+ On MRI abs_path may be unreliable in the face of Dir.chdir.
9
+
10
+
11
+ 0.0.4 (04-22-11)
12
+
13
+ - Using an undocumented API has changed in Rubinius 1.2.4dev. Down
14
+ the line, we need to get an API for RequireRelative#abs_file in
15
+ Rubinius. Until then, we'll have to change code.
16
+
17
+ 0.0.3 (09-27-10)
18
+
19
+ - Small .gemspec packaging issues
20
+
21
+ 0.0.2 (09-22-10)
22
+
23
+ - First public release.
data/README.textile ADDED
@@ -0,0 +1,13 @@
1
+ h2. Ruby 1.9's relative_relative for Rubinus and MRI 1.8
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,122 @@
1
+ #!/usr/bin/env rake
2
+ # -*- Ruby -*-
3
+ # Are we rubinius or MRI 1.8?
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 &&
9
+ RUBY_DESCRIPTION.start_with?('ruby 1.9.2frame')) ||
10
+ (RUBY_VERSION.start_with?('1.8') &&
11
+ RUBY_COPYRIGHT.end_with?('Yukihiro Matsumoto'))
12
+
13
+ # begin
14
+ # require_relative 'lib/version'
15
+ # puts 'Looks like you already have require_relative!'
16
+ # exit 5
17
+ # rescue NameError
18
+ # end
19
+
20
+ require 'rubygems'
21
+ require 'rubygems/package_task'
22
+ require 'rdoc/task'
23
+ require 'rake/testtask'
24
+ require 'fileutils'
25
+
26
+ ROOT_DIR = File.dirname(__FILE__)
27
+ require File.join(ROOT_DIR, '/lib/version')
28
+
29
+ def gemspec
30
+ @gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
31
+ end
32
+
33
+ def gem_file
34
+ "#{gemspec.name}-#{gemspec.version}-#{gemspec.platform.to_s}.gem"
35
+ end
36
+
37
+
38
+ desc "Build the gem"
39
+ task :package=>:gem
40
+ task :gem=>:gemspec do
41
+ sh "gem build .gemspec"
42
+ FileUtils.mkdir_p 'pkg'
43
+ FileUtils.mv gem_file, 'pkg'
44
+ end
45
+
46
+ task :default => [:test]
47
+
48
+ desc 'Install locally'
49
+ task :install => :package do
50
+ Dir.chdir(ROOT_DIR) do
51
+ sh %{gem install --local pkg/#{gem_file}}
52
+ end
53
+ end
54
+
55
+ desc 'Test everything.'
56
+ Rake::TestTask.new(:test) do |t|
57
+ t.libs << './lib'
58
+ t.pattern = 'test/test-*.rb'
59
+ t.options = '--verbose' if $VERBOSE
60
+ end
61
+ task :test => [:lib]
62
+
63
+ require 'rbconfig'
64
+ RUBY_PATH = File.join(RbConfig::CONFIG['bindir'],
65
+ RbConfig::CONFIG['RUBY_INSTALL_NAME'])
66
+
67
+ def run_standalone_ruby_file(directory)
68
+ # puts ('*' * 10) + ' ' + directory + ' ' + ('*' * 10)
69
+ Dir.chdir(directory) do
70
+ Dir.glob('test-rr.rb').each do |ruby_file|
71
+ # puts( ('-' * 20) + ' ' + ruby_file + ' ' + ('-' * 20))
72
+ system(RUBY_PATH, ruby_file)
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+ desc "Run each library Ruby file in standalone mode."
79
+ rake_dir = File.dirname(__FILE__)
80
+ task :check do
81
+ run_standalone_ruby_file(File.join(%W(#{rake_dir} test)))
82
+ end
83
+ task :default => [:test]
84
+
85
+ # Remove the above when I figure out what's up with the commented-out code.
86
+
87
+ desc 'Create a GNU-style ChangeLog via git2cl'
88
+ task :ChangeLog do
89
+ system('git log --pretty --numstat --summary | git2cl > ChangeLog')
90
+ end
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
+ desc 'Remove residue from running patch'
103
+ task :rm_patch_residue do
104
+ FileUtils.rm_rf FileList['**/*.{rej,orig}'].to_a, :verbose => true
105
+ end
106
+
107
+ desc 'Remove ~ backup files'
108
+ task :rm_tilde_backups do
109
+ FileUtils.rm_rf Dir.glob('**/*~'), :verbose => true
110
+ FileUtils.rm_rf Dir.glob('**/*.rbc'), :verbose => true
111
+ end
112
+
113
+ desc "Remove built files"
114
+ task :clean => [:clobber_package, :clobber_rdoc, :rm_patch_residue, :rm_tilde_backups]
115
+
116
+ task :clobber_package do
117
+ FileUtils.rm_rf File.join(ROOT_DIR, 'pkg')
118
+ end
119
+
120
+ task :clobber_rdoc do
121
+ FileUtils.rm_rf File.join(ROOT_DIR, 'doc')
122
+ end
@@ -0,0 +1,83 @@
1
+ # Ruby 1.9's require_relative.
2
+
3
+ if defined?(RubyVM) && RUBY_DESCRIPTION.start_with?('ruby 1.9.2frame')
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
+ else
20
+ file = caller.first.split(/:\d/,2).first
21
+ if /\A\((.*)\)/ =~ file # eval, etc.
22
+ nil
23
+ end
24
+ File.expand_path(file)
25
+ end
26
+ end
27
+ module_function :abs_file
28
+ end
29
+
30
+ if RUBY_VERSION.start_with?('1.9')
31
+ # On 1.9.2 platforms we don't do anything.
32
+ elsif defined?(Rubinius) && '1.8.7' == RUBY_VERSION
33
+ module Kernel
34
+ def require_relative(suffix)
35
+ # Rubinius::Location#file stores relative file names while
36
+ # Rubinius::Location#scope.current_script.data_path stores the
37
+ # absolute file name. It is possible (hopeful even) that in the
38
+ # future that Rubinius will change the API to be more
39
+ # intuitive. When that occurs, I'll change the below to that
40
+ # simpler thing.
41
+ scope = Rubinius::StaticScope.of_sender
42
+ script = scope.current_script
43
+ if script
44
+ require File.join(File.dirname(script.data_path), suffix)
45
+ else
46
+ raise LoadError "Something is wrong in trying to get relative path"
47
+ end
48
+ end
49
+ end
50
+ elsif (RUBY_VERSION.start_with?('1.8') &&
51
+ RUBY_COPYRIGHT.end_with?('Yukihiro Matsumoto'))
52
+ def require_relative(suffix)
53
+ file = caller.first.split(/:\d/,2).first
54
+ if /\A\((.*)\)/ =~ file # eval, etc.
55
+ raise LoadError, "require_relative is called in #{$1}"
56
+ end
57
+ require File.join(File.dirname(file), suffix)
58
+ end
59
+ end
60
+
61
+ # demo
62
+ if __FILE__ == $0
63
+ file = RequireRelative.abs_file
64
+ puts file
65
+ require 'tmpdir'
66
+ dir =
67
+ if RUBY_VERSION.start_with?('1.8') &&
68
+ RUBY_COPYRIGHT.end_with?('Yukihiro Matsumoto')
69
+ puts "Note: require_relative doesn't work with Dir.chdir as it does on Rubinius or 1.9"
70
+ '.'
71
+ else
72
+ Dir.tmpdir
73
+ end
74
+ Dir.chdir(dir) do
75
+ rel_file = File.basename(file)
76
+ cur_dir = File.basename(File.dirname(file))
77
+ ['./', "../#{cur_dir}/"].each do |prefix|
78
+ test = "#{prefix}#{rel_file}"
79
+ puts "#{test}: #{require_relative test}"
80
+ puts "#{test}: #{require_relative test} -- should be false"
81
+ end
82
+ end
83
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module RequireRelative
2
+ VERSION = '0.0.5'
3
+ end
data/test/bar.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Just something else to try require_relative on.
2
+ class Bar
3
+ end
data/test/foo.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Just something to try require_relative on.
2
+ class Foo
3
+ end
data/test/test-rr.rb ADDED
@@ -0,0 +1,36 @@
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
+ dir =
13
+ if RUBY_VERSION.start_with?('1.8') &&
14
+ RUBY_COPYRIGHT.end_with?('Yukihiro Matsumoto')
15
+ puts "Note: require_relative doesn't work with Dir.chdir as it does on Rubinius or 1.9"
16
+ '.'
17
+ else
18
+ Dir.tmpdir
19
+ end
20
+ abs_file = RequireRelative.abs_file
21
+ # The chdir is to make things harder for those platforms that
22
+ # truly support require_relative.
23
+ Dir.chdir(dir) do
24
+ cur_dir = File.basename(File.expand_path(File.dirname(abs_file)))
25
+ ['./foo', "../#{cur_dir}/bar"].each_with_index do |suffix, i|
26
+ assert_equal(true, require_relative(suffix),
27
+ "check require_relative(#{suffix})")
28
+ # Check that the require_relative worked by checking to see of the
29
+ # class from each file was imported.
30
+ assert_equal(Class, (0 == i ? Foo : Bar).class)
31
+ assert_equal(false, require_relative(suffix),
32
+ "require_relative(#{suffix}) second time should be false")
33
+ end
34
+ end
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbx-require-relative
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 5
10
+ version: 0.0.5
11
+ platform: universal-ruby-1.8.7
12
+ authors:
13
+ - R. Bernstein
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-11 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: |
23
+ Ruby 1.9's require_relative for Rubinius and MRI 1.8.
24
+
25
+ We also add abs_path which is like __FILE__ but __FILE__ can be fooled
26
+ by a sneaky "chdir" while abs_path can't.
27
+
28
+ If you are running on Ruby 1.9.2, require_relative is the pre-defined
29
+ version. The benefit we provide in this situation by this package is
30
+ the ability to write the same require_relative sequence in Rubinius
31
+ 1.8 and Ruby 1.9.
32
+
33
+ email: rockyb@rubyforge.net
34
+ executables: []
35
+
36
+ extensions: []
37
+
38
+ extra_rdoc_files: []
39
+
40
+ files:
41
+ - LICENSE
42
+ - ChangeLog
43
+ - NEWS
44
+ - README.textile
45
+ - Rakefile
46
+ - lib/version.rb
47
+ - lib/require_relative.rb
48
+ - test/test-rr.rb
49
+ - test/foo.rb
50
+ - test/bar.rb
51
+ has_rdoc: true
52
+ homepage: http://github.com/rocky/rbx-require-relative
53
+ licenses:
54
+ - MIT
55
+ post_install_message:
56
+ rdoc_options:
57
+ - --title
58
+ - require_relative 0.0.5 Documentation
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ hash: 57
67
+ segments:
68
+ - 1
69
+ - 8
70
+ - 7
71
+ version: 1.8.7
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 0
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.6.1
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Ruby 1.9's require_relative for Rubinius and MRI 1.8. 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.
88
+ test_files: []
89
+