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

Commit

Permalink
Update templates
Browse files Browse the repository at this point in the history
This fixes several rubocop and linter warnings, such as prefer usage of
single-quoted strings when string interpolation is no needed, and lines
that are too long.
  • Loading branch information
friederbluemle committed Dec 1, 2017
1 parent c3ea3dd commit e044bd4
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 71 deletions.
14 changes: 7 additions & 7 deletions lib/bundler/templates/Executable
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG["ruby_install_name"] %>
#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG['ruby_install_name'] %>
# frozen_string_literal: true

#
Expand All @@ -8,14 +8,14 @@
# this file is here to facilitate running it.
#

bundle_binstub = File.expand_path("../bundle", __FILE__)
bundle_binstub = File.expand_path('../bundle', __FILE__)
load(bundle_binstub) if File.file?(bundle_binstub)

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../<%= relative_gemfile_path %>",
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../<%= relative_gemfile_path %>',
Pathname.new(__FILE__).realpath)

require "rubygems"
require "bundler/setup"
require 'rubygems'
require 'bundler/setup'

load Gem.bin_path("<%= spec.name %>", "<%= executable %>")
load Gem.bin_path('<%= spec.name %>', '<%= executable %>')
28 changes: 14 additions & 14 deletions lib/bundler/templates/Executable.bundler
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG["ruby_install_name"] %>
#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG['ruby_install_name'] %>
# frozen_string_literal: true

#
Expand All @@ -8,7 +8,7 @@
# this file is here to facilitate running it.
#

require "rubygems"
require 'rubygems'

m = Module.new do
module_function
Expand All @@ -18,36 +18,36 @@ m = Module.new do
end

def env_var_version
ENV["BUNDLER_VERSION"]
ENV['BUNDLER_VERSION']
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1 || ">= 0.a"
bundler_version = $1 || '>= 0.a'
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
gemfile = ENV['BUNDLE_GEMFILE']
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../<%= relative_gemfile_path %>", __FILE__)
File.expand_path('../<%= relative_gemfile_path %>', __FILE__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
Expand All @@ -68,22 +68,22 @@ m = Module.new do
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile
ENV['BUNDLE_GEMFILE'] ||= gemfile

# must dup string for RG < 1.8 compatibility
activate_bundler(bundler_version.dup)
end

def activate_bundler(bundler_version)
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0")
bundler_version = "< 2"
if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new('2.0')
bundler_version = '< 2'
end
gem_error = activation_error_handling do
gem "bundler", bundler_version
gem 'bundler', bundler_version
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
require 'bundler/version'
end
return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`"
Expand All @@ -101,5 +101,5 @@ end
m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("<%= spec.name %>", "<%= executable %>")
load Gem.bin_path('<%= spec.name %>', '<%= executable %>')
end
10 changes: 5 additions & 5 deletions lib/bundler/templates/Executable.standalone
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG["ruby_install_name"] %>
#!/usr/bin/env <%= Bundler.settings[:shebang] || RbConfig::CONFIG['ruby_install_name'] %>
#
# This file was generated by Bundler.
#
# The application '<%= executable %>' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
require 'pathname'
path = Pathname.new(__FILE__)
$:.unshift File.expand_path "../<%= standalone_path %>", path.realpath
$:.unshift File.expand_path '../<%= standalone_path %>', path.realpath

require "bundler/setup"
load File.expand_path "../<%= executable_path %>", path.realpath
require 'bundler/setup'
load File.expand_path '../<%= executable_path %>', path.realpath
4 changes: 2 additions & 2 deletions lib/bundler/templates/Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

source "https://rubygems.org"
source 'https://rubygems.org'

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# gem "rails"
# gem 'rails'
4 changes: 2 additions & 2 deletions lib/bundler/templates/gems.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

# A sample gems.rb
source "https://rubygems.org"
source 'https://rubygems.org'

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

# gem "rails"
# gem 'rails'
6 changes: 3 additions & 3 deletions lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include:
Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
Expand Down Expand Up @@ -67,8 +67,8 @@ members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
2 changes: 1 addition & 1 deletion lib/bundler/templates/newgem/Gemfile.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source "https://rubygems.org"
source 'https://rubygems.org'

git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }

Expand Down
30 changes: 24 additions & 6 deletions lib/bundler/templates/newgem/README.md.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# <%= config[:constant_name] %>

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/<%= config[:namespaced_path] %>`. To experiment with that code, run `bin/console` for an interactive prompt.
Welcome to your new gem! In this directory, you'll find the files you need to be
able to package up your Ruby library into a gem. Put your Ruby code in the file
`lib/<%= config[:namespaced_path] %>`.
To experiment with that code, run `bin/console` for an interactive prompt.

TODO: Delete this and the text above, and describe your gem

Expand All @@ -26,22 +29,37 @@ TODO: Write usage instructions here

## Development

After checking out the repo, run `bin/setup` to install dependencies.<% if config[:test] %> Then, run `rake <%= config[:test].sub('mini', '').sub('rspec', 'spec') %>` to run the tests.<% end %> You can also run `bin/console` for an interactive prompt that will allow you to experiment.<% if config[:bin] %> Run `bundle exec <%= config[:name] %>` to use the gem in this directory, ignoring other installed copies of this gem.<% end %>
After checking out the repo, run `bin/setup` to install dependencies.
<% if config[:test] %>Then, run `rake <%= config[:test].sub('mini', '').sub('rspec', 'spec') %>` to run the tests.<% end %>
You can also run `bin/console` for an interactive prompt that will allow you to
experiment.
<% if config[:bin] %>Run `bundle exec <%= config[:name] %>` to use the gem in this directory, ignoring other installed copies of this gem.<% end %>

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
To install this gem onto your local machine, run `bundle exec rake install`. To
release a new version, update the version number in `version.rb`, and then run
`bundle exec rake release`, which will create a Git tag for the version, push
Git commits and tags, and push the `.gem` file to
[rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/<%= config[:github_username] %>/<%= config[:name] %>.<% if config[:coc] %> This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.<% end %>
Bug reports and pull requests are welcome on GitHub at
https://github.com/<%= config[:github_username] %>/<%= config[:name] %>.<% if config[:coc] %>
This project is intended to be a safe, welcoming space for collaboration, and
contributors are expected to adhere to the
[Contributor Covenant](http://contributor-covenant.org) code of conduct.<% end %>
<% if config[:mit] -%>

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
The gem is available as open source under the terms of the
[MIT License](https://opensource.org/licenses/MIT).
<% end -%>
<% if config[:coc] -%>

## Code of Conduct

Everyone interacting in the <%= config[:constant_name] %> project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/<%= config[:github_username] %>/<%= config[:name] %>/blob/master/CODE_OF_CONDUCT.md).
Everyone interacting in the <%= config[:constant_name] %> project’s
codebases, issue trackers, chat rooms and mailing lists is expected to follow
the [code of conduct](https://github.com/<%= config[:github_username] %>/<%= config[:name] %>/blob/master/CODE_OF_CONDUCT.md).
<% end -%>
8 changes: 4 additions & 4 deletions lib/bundler/templates/newgem/bin/console.tt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "<%= config[:namespaced_path] %>"
require 'bundler/setup'
require '<%= config[:namespaced_path] %>'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# require 'pry'
# Pry.start

require "irb"
require 'irb'
IRB.start(__FILE__)
2 changes: 1 addition & 1 deletion lib/bundler/templates/newgem/exe/newgem.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby

require "<%= config[:namespaced_path] %>"
require '<%= config[:namespaced_path] %>'
2 changes: 1 addition & 1 deletion lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
require "mkmf"
require 'mkmf'

create_makefile(<%= config[:makefile_path].inspect %>)
4 changes: 2 additions & 2 deletions lib/bundler/templates/newgem/lib/newgem.rb.tt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "<%= config[:namespaced_path] %>/version"
require '<%= config[:namespaced_path] %>/version'
<%- if config[:ext] -%>
require "<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>"
require '<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>'
<%- end -%>

<%- config[:constant_array].each_with_index do |c, i| -%>
Expand Down
29 changes: 15 additions & 14 deletions lib/bundler/templates/newgem/newgem.gemspec.tt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# coding: utf-8

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

Gem::Specification.new do |spec|
spec.name = <%= config[:name].inspect %>
Expand All @@ -14,36 +14,37 @@ Gem::Specification.new do |spec|

spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
spec.description = %q{TODO: Write a longer description or delete this line.}
spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.homepage = 'TODO: Insert website or public repo URL of your gem.'
<%- if config[:mit] -%>
spec.license = "MIT"
spec.license = 'MIT'
<%- end -%>

# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the
# 'allowed_push_host' to allow pushing to a single host or delete this section
# to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
raise 'RubyGems 2.0 or newer is required to protect against ' \
'public gem pushes.'
end

spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']
<%- if config[:ext] -%>
spec.extensions = ["ext/<%= config[:underscored_name] %>/extconf.rb"]
<%- end -%>

spec.add_development_dependency "bundler", "~> <%= config[:bundler_version] %>"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency 'bundler', '~> <%= config[:bundler_version] %>'
spec.add_development_dependency 'rake', '~> 10.0'
<%- if config[:ext] -%>
spec.add_development_dependency "rake-compiler"
spec.add_development_dependency 'rake-compiler'
<%- end -%>
<%- if config[:test] -%>
spec.add_development_dependency "<%= config[:test] %>", "~> <%= config[:test_framework_version] %>"
spec.add_development_dependency '<%= config[:test] %>', '~> <%= config[:test_framework_version] %>'
<%- end -%>
end
4 changes: 2 additions & 2 deletions lib/bundler/templates/newgem/spec/newgem_spec.rb.tt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
RSpec.describe <%= config[:constant_name] %> do
it "has a version number" do
it 'has a version number' do
expect(<%= config[:constant_name] %>::VERSION).not_to be nil
end

it "does something useful" do
it 'does something useful' do
expect(false).to eq(true)
end
end
6 changes: 3 additions & 3 deletions lib/bundler/templates/newgem/spec/spec_helper.rb.tt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "bundler/setup"
require "<%= config[:namespaced_path] %>"
require 'bundler/setup'
require '<%= config[:namespaced_path] %>'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
config.example_status_persistence_file_path = '.rspec_status'

# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/templates/newgem/test/newgem_test.rb.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "test_helper"
require 'test_helper'

class <%= config[:constant_name] %>Test < Minitest::Test
def test_that_it_has_a_version_number
Expand Down
6 changes: 3 additions & 3 deletions lib/bundler/templates/newgem/test/test_helper.rb.tt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "<%= config[:namespaced_path] %>"
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require '<%= config[:namespaced_path] %>'

require "minitest/autorun"
require 'minitest/autorun'

0 comments on commit e044bd4

Please sign in to comment.