gempilot 0.2.4 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ed510959d35011586d23fc0dcc0baff3a453a2acbd1a2d1c8fb4489cee63e6e0
4
- data.tar.gz: 455ba876df7b3fb40df26932737cae4062a6e6e2210f1fd02b18a231566bd23d
3
+ metadata.gz: 72e379c74f157a19076c82e54b15e2d3581610d11089542ebd32b346971cfdb5
4
+ data.tar.gz: e7b8f296a83f2c4b9e24f4bb3fd7757a034b1cca00fa461f4baa3e5c878b6f51
5
5
  SHA512:
6
- metadata.gz: 4ce5185ea5c07adc72435dee47b2f749f4f6146f26a09c8d8c557490e4be1b69b2b048e4c9ab32b8548d043c9a0d393cc32a0d8dd23c94c98cabd3a8737334d9
7
- data.tar.gz: 6094227a45e9bb173f0455dc155bd3ac7593698a7c41c7ac1482c5e7c44a59a90c547bb20206d3c7887b87a84977fc1f7ca615b2975fe53dc6a8ab85384a83e8
6
+ metadata.gz: bcb608a185c3808045cf017dcf0629d9b6034be93fd8457129728abed9cfd5191288893c214b3b38a46fdbda267676cdb7976ec2013c053a4b7796cd551a9c73
7
+ data.tar.gz: 867f02bab2332352a5035db336f5b1073f5d4a4f08f49f75b76b84eb2fdd4d490dba4c9f36fed4b60d0a7844791509dce074d3f13d488b08000e16bc0c70bdc8
data/.rubocop.yml CHANGED
@@ -279,17 +279,3 @@ RSpec/NamedSubject:
279
279
  # have_file_content matcher accepts a filename string in expect()
280
280
  RSpec/ExpectActual:
281
281
  Enabled: false
282
-
283
- Design/PositionalArguments:
284
- Enabled: false
285
-
286
- Design/KeywordArguments:
287
- Enabled: false
288
-
289
- Design/TotalArguments:
290
- Enabled: false
291
-
292
- Design/AgentNounClassName:
293
- Exclude:
294
- - 'lib/gempilot/generator.rb'
295
- - 'test/gempilot/cli/generator_test.rb'
@@ -18,16 +18,8 @@ RuboCop::RakeTask.new
18
18
  require "gempilot/version_task"
19
19
  Gempilot::VersionTask.new
20
20
 
21
- namespace :zeitwerk do
22
- desc "Verify all files follow Zeitwerk naming conventions"
23
- task :validate do
24
- ruby "-e", <<~RUBY
25
- require '<%= @require_path %>'
26
- <%= @module_name %>::LOADER.eager_load(force: true)
27
- puts 'Zeitwerk: All files loaded successfully.'
28
- RUBY
29
- end
30
- end
21
+ require "gempilot/zeitwerk_task"
22
+ Gempilot::ZeitwerkTask.new
31
23
 
32
24
  <% if @test_framework == :minitest -%>
33
25
  task default: [:test, :rubocop]
@@ -6,8 +6,7 @@ require "zeitwerk"
6
6
  ##
7
7
  # Top-level namespace for the <%= @gem_name %> gem.
8
8
  module <%= @module_name %>
9
- LOADER = Zeitwerk::Loader.for_gem
10
- LOADER.setup
9
+ LOADER = Zeitwerk::Loader.for_gem.tap(&:setup)
11
10
 
12
11
  ##
13
12
  # Base error class for <%= @gem_name %>.
@@ -9,8 +9,7 @@ require "zeitwerk"
9
9
  <% end -%>
10
10
  <%= " " * i %>module <%= part %>
11
11
  <% end -%>
12
- <%= " " * @module_parts.size %>LOADER = Zeitwerk::Loader.for_gem_extension(<%= @base_module %>)
13
- <%= " " * @module_parts.size %>LOADER.setup
12
+ <%= " " * @module_parts.size %>LOADER = Zeitwerk::Loader.for_gem_extension(<%= @base_module %>).tap(&:setup)
14
13
 
15
14
  <%= " " * @module_parts.size %>##
16
15
  <%= " " * @module_parts.size %># Base error class for <%= @gem_name %>.
@@ -1,7 +1,10 @@
1
1
  ENV["MT_NO_PLUGINS"] = "1" unless ENV["RM_INFO"]
2
2
 
3
3
  require "minitest/autorun"
4
- require "minitest/reporters"
5
- Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)]
4
+
5
+ unless ENV["RM_INFO"]
6
+ require "minitest/reporters"
7
+ Minitest::Reporters.use! [Minitest::Reporters::DefaultReporter.new(color: true)]
8
+ end
6
9
 
7
10
  require "<%= @require_path %>"
data/issues.rec CHANGED
@@ -95,7 +95,7 @@ Id: 4EB6E51C-4322-11F1-B1B2-FE6CB9572C2F
95
95
  Updated: Tue, 28 Apr 2026 12:50:05 -0400
96
96
  Title: Existing git repo on gempilot create needs new commit message
97
97
  Description: Currently it commits "Initial commit". Inappropriate for a git repo that already has a history
98
- Status: open
98
+ Status: closed
99
99
 
100
100
  Id: 0411D4DA-4323-11F1-847C-FE6CB9572C2F
101
101
  Updated: Tue, 28 Apr 2026 12:55:09 -0400
@@ -110,21 +110,21 @@ Description: e.g.
110
110
  + Zeitwerk::Loader.for_gem.tap do |l|
111
111
  + l.setup
112
112
  + end
113
- +
114
- +
115
- Status: open
113
+ +
114
+ +
115
+ Status: closed
116
116
 
117
117
  Id: 5618BB20-4325-11F1-BF5A-FE6CB9572C2F
118
118
  Updated: Tue, 28 Apr 2026 13:11:46 -0400
119
119
  Title: Move zeitwerk check task into gempilot
120
120
  Description: Can't iterate on it when its not managed by gempilot. A new feature needs to be added
121
- Status: open
121
+ Status: closed
122
122
 
123
123
  Id: 6BE168E4-4325-11F1-BE0F-FE6CB9572C2F
124
124
  Updated: Tue, 28 Apr 2026 13:12:22 -0400
125
125
  Title: Add zeitwerk:all task
126
126
  Description: Add rake task that runs LOADER.all_expected_cpaths and prints in a nice table, similar to rails routes
127
- Status: open
127
+ Status: closed
128
128
 
129
129
  Id: 56DB9634-4327-11F1-8D0F-FE6CB9572C2F
130
130
  Updated: Fri, 05 Jun 2026 00:00:00 -0400
@@ -155,13 +155,13 @@ Description: When doing `gempilot new Reversal::Server`, in a project called "re
155
155
  + create test/reversal/store_test.rb
156
156
  +
157
157
  + The test file is incorrectly named. Should be server_test.rb
158
- Status: open
158
+ Status: closed
159
159
 
160
160
  Id: F5486B48-71DB-11F1-980F-FE6CB9572C2E
161
161
  Updated: Fri, 26 Jun 2026 23:54:55 -0400
162
162
  Title: Rubymine <=> Minitest usage causes "no reporters allowed error"
163
163
  Description: Has to do with how the ENV var RM_INFO is being interpreted
164
- Status: open
164
+ Status: closed
165
165
 
166
166
  Id: 8D847572-7273-11F1-B508-FE6CB9572C2E
167
167
  Updated: Fri, 03 Jul 2026 22:38:22 +0000
@@ -97,9 +97,21 @@ module Gempilot
97
97
  cd @gem_name do
98
98
  sh "git", "init", "-q", "-b", @branch
99
99
  sh "git", "add", "."
100
- sh "git", "commit", "-q", "-m", "Initial commit."
100
+ sh "git", "commit", "-q", "-m", commit_message
101
101
  end
102
102
  end
103
+
104
+ # "Initial commit." is wrong when scaffolding into a directory that is
105
+ # already a repository with history (e.g. a cloned remote), so name the
106
+ # commit after the gem in that case.
107
+ def commit_message
108
+ existing_history? ? "Add #{@gem_name} gem scaffolding." : "Initial commit."
109
+ end
110
+
111
+ def existing_history?
112
+ system("git", "rev-parse", "--verify", "--quiet", "HEAD",
113
+ out: File::NULL, err: File::NULL)
114
+ end
103
115
  end
104
116
  end
105
117
  end
@@ -30,18 +30,14 @@ module Gempilot
30
30
 
31
31
  ## Path to the constant's source file, e.g. +lib/my_gem/services/auth.rb+.
32
32
  def lib_path
33
- "#{File.join("lib", *path_segments)}.rb"
33
+ path_for("lib", ".rb")
34
34
  end
35
35
 
36
36
  ## Path to the constant's test file for +framework+ (+:rspec+ or
37
- ## +:minitest+); correct for multi-segment (hyphenated) gem modules.
37
+ ## +:minitest+). Mirrors +lib_path+ so the test always tracks the source,
38
+ ## including for multi-segment (hyphenated) gem modules.
38
39
  def test_path(framework)
39
- rest = path_segments.drop(require_path.split("/").length)
40
- if framework == :rspec
41
- "#{File.join("spec", require_path, *rest)}_spec.rb"
42
- else
43
- "#{File.join("test", require_path, *rest)}_test.rb"
44
- end
40
+ framework == :rspec ? path_for("spec", "_spec.rb") : path_for("test", "_test.rb")
45
41
  end
46
42
 
47
43
  private
@@ -57,5 +53,9 @@ module Gempilot
57
53
  def path_segments
58
54
  parts.map(&:underscore)
59
55
  end
56
+
57
+ def path_for(root, suffix)
58
+ "#{File.join(root, *path_segments)}#{suffix}"
59
+ end
60
60
  end
61
61
  end
@@ -33,8 +33,16 @@ module Gempilot
33
33
  project_segments.join("-")
34
34
  end
35
35
 
36
+ def require_path
37
+ project_segments.join("/")
38
+ end
39
+
40
+ def module_name
41
+ project_segments.map(&:camelize).join("::")
42
+ end
43
+
36
44
  def klass
37
- Object.const_get(project_segments.map(&:camelize).join("::"))
45
+ Object.const_get(module_name)
38
46
  end
39
47
 
40
48
  def version
@@ -1,3 +1,3 @@
1
1
  module Gempilot
2
- VERSION = "0.2.4".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
@@ -0,0 +1,61 @@
1
+ require "rake/tasklib"
2
+ require_relative "../gempilot"
3
+
4
+ module Gempilot
5
+ ## Rake tasks for validating and inspecting a gem's Zeitwerk loader.
6
+ ##
7
+ ## Owned by gempilot and consumed by generated gems via
8
+ ## <tt>require "gempilot/zeitwerk_task"; Gempilot::ZeitwerkTask.new</tt>, so
9
+ ## the logic rolls forward on a gempilot bump instead of being copied into
10
+ ## every gem's Rakefile. Each task boots a clean child process so eager
11
+ ## loading surfaces naming errors without polluting the Rake process.
12
+ class ZeitwerkTask < Rake::TaskLib
13
+ attr_reader :project
14
+
15
+ def initialize(root: Dir.pwd)
16
+ super()
17
+ @project = Project.new(root)
18
+ define_tasks
19
+ end
20
+
21
+ private
22
+
23
+ def define_tasks
24
+ namespace :zeitwerk do
25
+ define_validate_task
26
+ define_all_task
27
+ end
28
+ end
29
+
30
+ def define_validate_task
31
+ desc "Verify all files follow Zeitwerk naming conventions"
32
+ task(:validate) { ruby "-Ilib", "-e", validate_script }
33
+ end
34
+
35
+ def define_all_task
36
+ desc "List every constant Zeitwerk manages and the file it expects"
37
+ task(:all) { ruby "-Ilib", "-e", all_script }
38
+ end
39
+
40
+ def loader
41
+ "#{project.module_name}::LOADER"
42
+ end
43
+
44
+ def validate_script
45
+ <<~RUBY
46
+ require '#{project.require_path}'
47
+ #{loader}.eager_load(force: true)
48
+ puts 'Zeitwerk: All files loaded successfully.'
49
+ RUBY
50
+ end
51
+
52
+ def all_script
53
+ <<~RUBY
54
+ require '#{project.require_path}'
55
+ rows = #{loader}.all_expected_cpaths.sort_by(&:last)
56
+ width = rows.map { |_path, cpath| cpath.length }.max || 0
57
+ rows.each { |path, cpath| puts format("%-\#{width}s %s", cpath, path) }
58
+ RUBY
59
+ end
60
+ end
61
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gempilot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Gillis
@@ -134,6 +134,7 @@ files:
134
134
  - lib/gempilot/version.rb
135
135
  - lib/gempilot/version_tag.rb
136
136
  - lib/gempilot/version_task.rb
137
+ - lib/gempilot/zeitwerk_task.rb
137
138
  - vendor/vendored.gemv
138
139
  homepage: https://github.com/gillisd/gempilot
139
140
  licenses: