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

Commit

Permalink
Use __dir__ instead of __FILE__ in newgem.gemspec template
Browse files Browse the repository at this point in the history
### 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
koic committed Apr 23, 2018
1 parent 257fb54 commit 00fd58e
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 00fd58e

Please sign in to comment.