rbx-require-relative 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,41 @@
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
+
1
39
  2010-09-23 rocky <rockyb@rubyforge.org>
2
40
 
3
41
  * .gemspec: Need symbol in defined?
data/NEWS CHANGED
@@ -1,3 +1,19 @@
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
+
1
17
  0.0.3 (09-27-10)
2
18
 
3
19
  - Small .gemspec packaging issues
@@ -1,4 +1,4 @@
1
- h2. Ruby 1.9's relative_relative for Rubinus 1.0.1 .. 1.1
1
+ h2. Ruby 1.9's relative_relative for Rubinus and MRI 1.8
2
2
 
3
3
  Here we add in Module RequireRelative method: *require_relative*, and *abs_file*. Example:
4
4
 
data/Rakefile CHANGED
@@ -1,21 +1,25 @@
1
1
  #!/usr/bin/env rake
2
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
- begin
10
- require_relative 'lib/version'
11
- puts 'Looks like you already have require_relative!'
12
- exit 5
13
- rescue NameError
14
- end
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
15
19
 
16
20
  require 'rubygems'
17
- require 'rake/gempackagetask'
18
- require 'rake/rdoctask'
21
+ require 'rubygems/package_task'
22
+ require 'rdoc/task'
19
23
  require 'rake/testtask'
20
24
  require 'fileutils'
21
25
 
@@ -26,12 +30,22 @@ def gemspec
26
30
  @gemspec ||= eval(File.read('.gemspec'), binding, '.gemspec')
27
31
  end
28
32
 
33
+ def gem_file
34
+ if (RUBY_VERSION.start_with?('1.8') &&
35
+ RUBY_COPYRIGHT.end_with?('Yukihiro Matsumoto'))
36
+ "#{gemspec.name}-#{gemspec.version}.gem"
37
+ else
38
+ "#{gemspec.name}-#{gemspec.version}-#{gemspec.platform.to_s}.gem"
39
+ end
40
+ end
41
+
42
+
29
43
  desc "Build the gem"
30
44
  task :package=>:gem
31
45
  task :gem=>:gemspec do
32
46
  sh "gem build .gemspec"
33
47
  FileUtils.mkdir_p 'pkg'
34
- FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
48
+ FileUtils.mv gem_file, 'pkg'
35
49
  end
36
50
 
37
51
  task :default => [:test]
@@ -39,7 +53,7 @@ task :default => [:test]
39
53
  desc 'Install locally'
40
54
  task :install => :package do
41
55
  Dir.chdir(ROOT_DIR) do
42
- sh %{gem install --local pkg/#{gemspec.name}-#{gemspec.version}}
56
+ sh %{gem install --local pkg/#{gem_file}}
43
57
  end
44
58
  end
45
59
 
@@ -47,7 +61,7 @@ desc 'Test everything.'
47
61
  Rake::TestTask.new(:test) do |t|
48
62
  t.libs << './lib'
49
63
  t.pattern = 'test/test-*.rb'
50
- t.verbose = true
64
+ t.options = '--verbose' if $VERBOSE
51
65
  end
52
66
  task :test => [:lib]
53
67
 
@@ -80,9 +94,6 @@ task :ChangeLog do
80
94
  system('git log --pretty --numstat --summary | git2cl > ChangeLog')
81
95
  end
82
96
 
83
- desc "Remove built files"
84
- task :clean => [:clobber_package, :clobber_rdoc]
85
-
86
97
  desc "Generate the gemspec"
87
98
  task :generate do
88
99
  puts gemspec.to_ruby
@@ -93,6 +104,20 @@ task :gemspec do
93
104
  gemspec.validate
94
105
  end
95
106
 
107
+ desc 'Remove residue from running patch'
108
+ task :rm_patch_residue do
109
+ FileUtils.rm_rf FileList['**/*.{rej,orig}'].to_a, :verbose => true
110
+ end
111
+
112
+ desc 'Remove ~ backup files'
113
+ task :rm_tilde_backups do
114
+ FileUtils.rm_rf Dir.glob('**/*~'), :verbose => true
115
+ FileUtils.rm_rf Dir.glob('**/*.rbc'), :verbose => true
116
+ end
117
+
118
+ desc "Remove built files"
119
+ task :clean => [:clobber_package, :clobber_rdoc, :rm_patch_residue, :rm_tilde_backups]
120
+
96
121
  task :clobber_package do
97
122
  FileUtils.rm_rf File.join(ROOT_DIR, 'pkg')
98
123
  end
@@ -1,30 +1,77 @@
1
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
+
2
7
  module RequireRelative
3
8
  def abs_file
4
- Rubinius::VM.backtrace(1)[0].method.scope.data_path
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
5
26
  end
6
27
  module_function :abs_file
7
28
  end
8
-
9
- module Kernel
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'))
10
52
  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)
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)
19
58
  end
20
59
  end
21
-
60
+
22
61
  # demo
23
62
  if __FILE__ == $0
24
63
  file = RequireRelative.abs_file
25
64
  puts file
26
65
  require 'tmpdir'
27
- Dir.chdir(Dir.tmpdir) do
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
28
75
  rel_file = File.basename(file)
29
76
  cur_dir = File.basename(File.dirname(file))
30
77
  ['./', "../#{cur_dir}/"].each do |prefix|
@@ -1,3 +1,3 @@
1
1
  module RequireRelative
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.5'
3
3
  end
@@ -9,9 +9,18 @@ require file
9
9
  class TestRR < Test::Unit::TestCase
10
10
  require 'tmpdir'
11
11
  def test_basic
12
- # The chdir is to make things harder.
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
13
20
  abs_file = RequireRelative.abs_file
14
- Dir.chdir(Dir.tmpdir) do
21
+ # The chdir is to make things harder for those platforms that
22
+ # truly support require_relative.
23
+ Dir.chdir(dir) do
15
24
  cur_dir = File.basename(File.expand_path(File.dirname(abs_file)))
16
25
  ['./foo', "../#{cur_dir}/bar"].each_with_index do |suffix, i|
17
26
  assert_equal(true, require_relative(suffix),
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbx-require-relative
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
4
+ hash: 21
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - R. Bernstein
@@ -15,13 +15,20 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-27 00:00:00 -04:00
18
+ date: 2011-06-11 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
22
  description: |
23
+ Ruby 1.9's require_relative for Rubinius and MRI 1.8.
23
24
 
24
- Ruby 1.9's require_relative for Rubinius
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.
25
32
 
26
33
  email: rockyb@rubyforge.net
27
34
  executables: []
@@ -47,10 +54,8 @@ licenses:
47
54
  - MIT
48
55
  post_install_message:
49
56
  rdoc_options:
50
- - --main
51
- - README
52
57
  - --title
53
- - require_relative 0.0.3 Documentation
58
+ - require_relative 0.0.5 Documentation
54
59
  require_paths:
55
60
  - lib
56
61
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -76,9 +81,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
81
  requirements: []
77
82
 
78
83
  rubyforge_project:
79
- rubygems_version: 1.3.6
84
+ rubygems_version: 1.6.1
80
85
  signing_key:
81
86
  specification_version: 3
82
- summary: Ruby 1.9's require_relative for Rubinius
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.
83
88
  test_files: []
84
89