Skip to content

Commit

Permalink
Auto merge of rubygems#6503 - koic:use_dir_instead_of_file_in_newgem_…
Browse files Browse the repository at this point in the history
…template, r=hsbt

Use `__dir__` instead of `__FILE__` in newgem.gemspec template

### What was the end-user problem that led to this PR?

Since Ruby 2.0 we've had `__dir__` as well as `__FILE__`.

The initial gem codes written with `bundle gem` using Ruby 2.0 or higher is an old description using `__FILE__`.

### What was your diagnosis of the problem?

Ruby 1.9 is EOL, so I think that there is not much Gem to start developed using it.

### What is your fix for the problem, implemented in this PR?

This PR uses `__dir__` when starting Gem development (i.e. `bundle gem`) using Ruby 2.0 or higher version.
  • Loading branch information
bundlerbot committed Apr 28, 2018
2 parents 9487710 + 00fd58e commit 0c5d3b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/bundler/templates/newgem/newgem.gemspec.tt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<%- if RUBY_VERSION < "2.0.0" -%>
# coding: utf-8

<%- end -%>
lib = File.expand_path("../lib", __FILE__)
<%- else -%>
lib = File.expand_path("lib", __dir__)
<%- end -%>
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "<%= config[:namespaced_path] %>/version"

Expand Down
4 changes: 4 additions & 0 deletions lib/bundler/templates/newgem/test/test_helper.rb.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<%- if RUBY_VERSION < "2.0.0" -%>
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
<%- else -%>
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
<%- end -%>
require "<%= config[:namespaced_path] %>"

require "minitest/autorun"

0 comments on commit 0c5d3b8

Please sign in to comment.