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

Commit

Permalink
Auto merge of #6267 - christhekeele:scaffold-error-class, r=colby-swa…
Browse files Browse the repository at this point in the history
…ndale

Add base error class to new gems.

Closes #6260.

Room for discussion:

- Which error class to use (`StandardError` makes sense to me)
- What formatting to use (the three-lines-with-comment seemed nicest to me)
- Whether or not using the flag to provide a different error base class is useful, and if it should validate the user's choice or not (I threw it in because it seemed harmless; is it? a boolean flag would work fine too)

---

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

Libraries don't always follow best practice from discussion in linked issue.

### What was your diagnosis of the problem?

Bundler could encourage best practice by adding it to the gem scaffold.

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

I added a base error class to the templates, and provided a flag to change/disable this behaviour.

### Why did you choose this fix out of the possible options?

Like any best-practice-by-default, this could ruin someones workflow/go against someone's preferences so I made it as configurable as possible.
  • Loading branch information
bundlerbot committed Jan 23, 2018
2 parents 350772f + 7482550 commit 3aa29ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/bundler/templates/newgem/lib/newgem.rb.tt
Expand Up @@ -6,6 +6,7 @@ require "<%= config[:namespaced_path] %>/<%= config[:underscored_name] %>"
<%- config[:constant_array].each_with_index do |c, i| -%>
<%= " " * i %>module <%= c %>
<%- end -%>
<%= " " * config[:constant_array].size %>class Error < StandardError; end %>
<%= " " * config[:constant_array].size %># Your code goes here...
<%- (config[:constant_array].size-1).downto(0) do |i| -%>
<%= " " * i %>end
Expand Down
4 changes: 4 additions & 0 deletions spec/commands/newgem_spec.rb
Expand Up @@ -310,6 +310,10 @@ def create_temporary_dir(dir)
expect(bundled_app("test_gem/lib/test_gem.rb").read).to match(%r{require "test_gem/version"})
end

it "creates a base error class" do
expect(bundled_app("test_gem/lib/test_gem.rb").read).to include("class Error < StandardError")
end

it "runs rake without problems" do
system_gems ["rake-10.0.2"]

Expand Down

0 comments on commit 3aa29ce

Please sign in to comment.