rbx-require-relative 0.0.6-universal-jruby-1.2

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,27 @@
1
+ 0.0.6 (02-22-12)
2
+
3
+ Allow Ruby 1.9.3
4
+
5
+ 0.0.5 (06-12-11) Fleetwood release
6
+
7
+ Allow this to work on Ruby MRI 1.8 and 1.9. On 1.9 we don't do
8
+ anything for require_relative, but in 1.9.2+thread_frame we add a
9
+ relible abs_path. This package is provided on 1.9 is there for
10
+ compatibility and for abs_path for a threadframe-enabled 1.9.2.
11
+
12
+ On MRI abs_path may be unreliable in the face of Dir.chdir.
13
+
14
+
15
+ 0.0.4 (04-22-11)
16
+
17
+ - Using an undocumented API has changed in Rubinius 1.2.4dev. Down
18
+ the line, we need to get an API for RequireRelative#abs_file in
19
+ Rubinius. Until then, we'll have to change code.
20
+
21
+ 0.0.3 (09-27-10)
22
+
23
+ - Small .gemspec packaging issues
24
+
25
+ 0.0.2 (09-22-10)
26
+
27
+ - 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,84 @@
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
+ RUBY_ENGINE == 'jruby')
53
+ def require_relative(suffix)
54
+ file = caller.first.split(/:\d/,2).first
55
+ if /\A\((.*)\)/ =~ file # eval, etc.
56
+ raise LoadError, "require_relative is called in #{$1}"
57
+ end
58
+ require File.join(File.dirname(file), suffix)
59
+ end
60
+ end
61
+
62
+ # demo
63
+ if __FILE__ == $0
64
+ file = RequireRelative.abs_file
65
+ puts file
66
+ require 'tmpdir'
67
+ dir =
68
+ if RUBY_VERSION.start_with?('1.8') &&
69
+ RUBY_COPYRIGHT.end_with?('Yukihiro Matsumoto')
70
+ puts "Note: require_relative doesn't work with Dir.chdir as it does on Rubinius or 1.9"
71
+ '.'
72
+ else
73
+ Dir.tmpdir
74
+ end
75
+ Dir.chdir(dir) do
76
+ rel_file = File.basename(file)
77
+ cur_dir = File.basename(File.dirname(file))
78
+ ['./', "../#{cur_dir}/"].each do |prefix|
79
+ test = "#{prefix}#{rel_file}"
80
+ puts "#{test}: #{require_relative test}"
81
+ puts "#{test}: #{require_relative test} -- should be false"
82
+ end
83
+ end
84
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module RequireRelative
2
+ VERSION = '0.0.6'
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,37 @@
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
+ RUBY_ENGINE == 'jruby')
16
+ puts "Note: require_relative doesn't work with Dir.chdir as it does on Rubinius or 1.9"
17
+ '.'
18
+ else
19
+ Dir.tmpdir
20
+ end
21
+ abs_file = RequireRelative.abs_file
22
+ # The chdir is to make things harder for those platforms that
23
+ # truly support require_relative.
24
+ Dir.chdir(dir) do
25
+ cur_dir = File.basename(File.expand_path(File.dirname(abs_file)))
26
+ ['./foo', "../#{cur_dir}/bar"].each_with_index do |suffix, i|
27
+ assert_equal(true, require_relative(suffix),
28
+ "check require_relative(#{suffix})")
29
+ # Check that the require_relative worked by checking to see of the
30
+ # class from each file was imported.
31
+ assert_equal(Class, (0 == i ? Foo : Bar).class)
32
+ assert_equal(false, require_relative(suffix),
33
+ "require_relative(#{suffix}) second time should be false")
34
+ end
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbx-require-relative
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 6
9
+ version: 0.0.6
10
+ platform: universal-jruby-1.2
11
+ authors:
12
+ - R. Bernstein
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-02-22 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: |
22
+ Ruby 1.9's require_relative for Rubinius and MRI 1.8.
23
+
24
+ We also add abs_path which is like __FILE__ but __FILE__ can be fooled
25
+ by a sneaky "chdir" while abs_path can't.
26
+
27
+ If you are running on Ruby 1.9 or greater, require_relative is the
28
+ pre-defined version. The benefit we provide in this situation by this
29
+ package is the ability to write the same require_relative sequence in
30
+ Rubinius 1.8 and Ruby 1.9.
31
+
32
+ email: rockyb@rubyforge.net
33
+ executables: []
34
+
35
+ extensions: []
36
+
37
+ extra_rdoc_files: []
38
+
39
+ files:
40
+ - LICENSE
41
+ - ChangeLog
42
+ - NEWS
43
+ - README.textile
44
+ - Rakefile
45
+ - lib/version.rb
46
+ - lib/require_relative.rb
47
+ - test/test-rr.rb
48
+ - test/foo.rb
49
+ - test/bar.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/rocky/rbx-require-relative
52
+ licenses:
53
+ - MIT
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --title
57
+ - require_relative 0.0.6 Documentation
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ~>
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 1
66
+ - 8
67
+ - 7
68
+ version: 1.8.7
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
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 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 or greater, 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.
83
+ test_files: []
84
+