Skip to content
This repository was archived by the owner on Apr 14, 2021. It is now read-only.

Commit 0c5d3b8

Browse files
committed
Auto merge of #6503 - koic:use_dir_instead_of_file_in_newgem_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.
2 parents 9487710 + 00fd58e commit 0c5d3b8

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/bundler/templates/newgem/newgem.gemspec.tt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<%- if RUBY_VERSION < "2.0.0" -%>
22
# coding: utf-8
33

4-
<%- end -%>
54
lib = File.expand_path("../lib", __FILE__)
5+
<%- else -%>
6+
lib = File.expand_path("lib", __dir__)
7+
<%- end -%>
68
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
79
require "<%= config[:namespaced_path] %>/version"
810

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
<%- if RUBY_VERSION < "2.0.0" -%>
12
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3+
<%- else -%>
4+
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
5+
<%- end -%>
26
require "<%= config[:namespaced_path] %>"
37

48
require "minitest/autorun"

0 commit comments

Comments
 (0)