gemsmith 15.5.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/LICENSE.adoc +207 -155
  4. data/README.adoc +177 -189
  5. data/exe/gemsmith +6 -0
  6. data/gemsmith.gemspec +41 -0
  7. data/lib/gemsmith/builders/bundler.rb +34 -0
  8. data/lib/gemsmith/builders/cli.rb +86 -0
  9. data/lib/gemsmith/builders/git/commit.rb +46 -0
  10. data/lib/gemsmith/builders/git/ignore.rb +37 -0
  11. data/lib/gemsmith/builders/rspec/helper.rb +47 -0
  12. data/lib/gemsmith/builders/specification.rb +35 -0
  13. data/lib/gemsmith/cli/actions/build.rb +53 -0
  14. data/lib/gemsmith/cli/actions/config.rb +35 -0
  15. data/lib/gemsmith/cli/actions/edit.rb +38 -0
  16. data/lib/gemsmith/cli/actions/install.rb +36 -0
  17. data/lib/gemsmith/cli/actions/publish.rb +36 -0
  18. data/lib/gemsmith/cli/actions/view.rb +38 -0
  19. data/lib/gemsmith/cli/parser.rb +33 -0
  20. data/lib/gemsmith/cli/parsers/build.rb +54 -0
  21. data/lib/gemsmith/cli/parsers/core.rb +94 -0
  22. data/lib/gemsmith/cli/shell.rb +66 -0
  23. data/lib/gemsmith/configuration/enhancers/template_root.rb +20 -0
  24. data/lib/gemsmith/configuration/loader.rb +50 -0
  25. data/lib/gemsmith/container.rb +21 -0
  26. data/lib/gemsmith/gems/finder.rb +21 -0
  27. data/lib/gemsmith/gems/loader.rb +21 -0
  28. data/lib/gemsmith/gems/picker.rb +43 -0
  29. data/lib/gemsmith/gems/presenter.rb +50 -0
  30. data/lib/gemsmith/templates/%project_name%/%project_name%.gemspec.erb +49 -0
  31. data/lib/gemsmith/templates/%project_name%/exe/%project_name%.erb +5 -0
  32. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/actions/config.rb.erb +35 -0
  33. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb +31 -0
  34. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parsers/core.rb.erb +54 -0
  35. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/shell.rb.erb +38 -0
  36. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/configuration/content.rb.erb +18 -0
  37. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/configuration/defaults.yml.erb +0 -0
  38. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/configuration/loader.rb.erb +33 -0
  39. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/container.rb.erb +35 -0
  40. data/lib/gemsmith/templates/{%gem_name%/lib/%gem_path%/identity.rb.tt → %project_name%/lib/%project_path%/identity.rb.erb} +1 -1
  41. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/actions/config_spec.rb.erb +24 -0
  42. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/parser_spec.rb.erb +25 -0
  43. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/parsers/core_spec.rb.erb +53 -0
  44. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/shell_spec.rb.erb +43 -0
  45. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/configuration/content_spec.rb.erb +15 -0
  46. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/configuration/loader_spec.rb.erb +29 -0
  47. data/lib/gemsmith/templates/%project_name%/spec/support/shared_contexts/application_container.rb.erb +22 -0
  48. data/lib/gemsmith/templates/%project_name%/spec/support/shared_examples/a_parser.rb.erb +7 -0
  49. data/lib/gemsmith/tools/cleaner.rb +29 -0
  50. data/lib/gemsmith/tools/editor.rb +30 -0
  51. data/lib/gemsmith/tools/installer.rb +39 -0
  52. data/lib/gemsmith/tools/packager.rb +33 -0
  53. data/lib/gemsmith/tools/publisher.rb +34 -0
  54. data/lib/gemsmith/tools/pusher.rb +36 -0
  55. data/lib/gemsmith/tools/validator.rb +28 -0
  56. data/lib/gemsmith/tools/versioner.rb +43 -0
  57. data/lib/gemsmith/tools/viewer.rb +28 -0
  58. data/lib/gemsmith.rb +5 -3
  59. data.tar.gz.sig +0 -0
  60. metadata +87 -115
  61. metadata.gz.sig +0 -0
  62. data/bin/gemsmith +0 -9
  63. data/lib/gemsmith/authenticators/basic.rb +0 -28
  64. data/lib/gemsmith/authenticators/ruby_gems.rb +0 -41
  65. data/lib/gemsmith/cli.rb +0 -259
  66. data/lib/gemsmith/credentials.rb +0 -82
  67. data/lib/gemsmith/errors/base.rb +0 -9
  68. data/lib/gemsmith/errors/requirement_conversion.rb +0 -9
  69. data/lib/gemsmith/errors/requirement_operator.rb +0 -9
  70. data/lib/gemsmith/errors/specification.rb +0 -9
  71. data/lib/gemsmith/gem/inspector.rb +0 -30
  72. data/lib/gemsmith/gem/module_formatter.rb +0 -50
  73. data/lib/gemsmith/gem/requirement.rb +0 -55
  74. data/lib/gemsmith/gem/specification.rb +0 -74
  75. data/lib/gemsmith/generators/base.rb +0 -46
  76. data/lib/gemsmith/generators/bundler.rb +0 -19
  77. data/lib/gemsmith/generators/bundler_audit.rb +0 -15
  78. data/lib/gemsmith/generators/circle_ci.rb +0 -14
  79. data/lib/gemsmith/generators/cli.rb +0 -17
  80. data/lib/gemsmith/generators/documentation.rb +0 -36
  81. data/lib/gemsmith/generators/engine.rb +0 -77
  82. data/lib/gemsmith/generators/gem.rb +0 -29
  83. data/lib/gemsmith/generators/git.rb +0 -45
  84. data/lib/gemsmith/generators/git_hub.rb +0 -15
  85. data/lib/gemsmith/generators/git_lint.rb +0 -14
  86. data/lib/gemsmith/generators/guard.rb +0 -14
  87. data/lib/gemsmith/generators/pragma.rb +0 -49
  88. data/lib/gemsmith/generators/rake.rb +0 -76
  89. data/lib/gemsmith/generators/reek.rb +0 -17
  90. data/lib/gemsmith/generators/rspec.rb +0 -39
  91. data/lib/gemsmith/generators/rubocop.rb +0 -18
  92. data/lib/gemsmith/generators/ruby.rb +0 -12
  93. data/lib/gemsmith/helpers/cli.rb +0 -59
  94. data/lib/gemsmith/helpers/template.rb +0 -30
  95. data/lib/gemsmith/identity.rb +0 -12
  96. data/lib/gemsmith/rake/builder.rb +0 -57
  97. data/lib/gemsmith/rake/publisher.rb +0 -100
  98. data/lib/gemsmith/rake/setup.rb +0 -4
  99. data/lib/gemsmith/rake/tasks.rb +0 -83
  100. data/lib/gemsmith/templates/%gem_name%/%gem_name%.gemspec.tt +0 -44
  101. data/lib/gemsmith/templates/%gem_name%/.circleci/config.yml.tt +0 -31
  102. data/lib/gemsmith/templates/%gem_name%/.github/ISSUE_TEMPLATE.md.tt +0 -14
  103. data/lib/gemsmith/templates/%gem_name%/.github/PULL_REQUEST_TEMPLATE.md.tt +0 -11
  104. data/lib/gemsmith/templates/%gem_name%/.gitignore.tt +0 -6
  105. data/lib/gemsmith/templates/%gem_name%/.reek.yml.tt +0 -6
  106. data/lib/gemsmith/templates/%gem_name%/.rubocop.yml.tt +0 -15
  107. data/lib/gemsmith/templates/%gem_name%/.ruby-version.tt +0 -1
  108. data/lib/gemsmith/templates/%gem_name%/CHANGES.md.tt +0 -3
  109. data/lib/gemsmith/templates/%gem_name%/CODE_OF_CONDUCT.md.tt +0 -66
  110. data/lib/gemsmith/templates/%gem_name%/CONTRIBUTING.md.tt +0 -22
  111. data/lib/gemsmith/templates/%gem_name%/Gemfile.tt +0 -47
  112. data/lib/gemsmith/templates/%gem_name%/Guardfile.tt +0 -21
  113. data/lib/gemsmith/templates/%gem_name%/LICENSE.md.tt +0 -20
  114. data/lib/gemsmith/templates/%gem_name%/README.md.tt +0 -93
  115. data/lib/gemsmith/templates/%gem_name%/Rakefile.tt +0 -12
  116. data/lib/gemsmith/templates/%gem_name%/bin/%gem_name%.tt +0 -8
  117. data/lib/gemsmith/templates/%gem_name%/bin/console.tt +0 -10
  118. data/lib/gemsmith/templates/%gem_name%/bin/setup.tt +0 -8
  119. data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%/cli.rb.tt +0 -61
  120. data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%/engine.rb.tt +0 -6
  121. data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%.rb.tt +0 -7
  122. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/install/USAGE.tt +0 -8
  123. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/install/install_generator.rb.tt +0 -12
  124. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/upgrade/USAGE.tt +0 -8
  125. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/upgrade/upgrade_generator.rb.tt +0 -10
  126. data/lib/gemsmith/templates/%gem_name%/spec/lib/%gem_path%/cli_spec.rb.tt +0 -81
  127. data/lib/gemsmith/templates/%gem_name%/spec/rails_helper.rb.tt +0 -14
  128. data/lib/gemsmith/templates/%gem_name%/spec/spec_helper.rb.tt +0 -37
  129. data/lib/gemsmith/templates/%gem_name%/spec/support/shared_contexts/temp_dir.rb.tt +0 -9
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates Command Line Interface (CLI) support.
6
- class CLI < Base
7
- def run
8
- return unless configuration.dig :generate, :cli
9
-
10
- template "%gem_name%/bin/%gem_name%.tt"
11
- template "%gem_name%/lib/%gem_path%/cli.rb.tt"
12
- template "%gem_name%/spec/lib/%gem_path%/cli_spec.rb.tt"
13
- cli.chmod "#{gem_name}/bin/#{gem_name}", 0o755
14
- end
15
- end
16
- end
17
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "tocer"
4
-
5
- module Gemsmith
6
- module Generators
7
- # Generates documentation support.
8
- class Documentation < Base
9
- def initialize cli, configuration: {}, writer: Tocer::Writer.new
10
- super cli, configuration: configuration
11
- @writer = writer
12
- end
13
-
14
- def run
15
- create_files
16
- update_readme
17
- end
18
-
19
- private
20
-
21
- attr_reader :writer
22
-
23
- def create_files
24
- template "%gem_name%/README.md.tt"
25
- template "%gem_name%/CONTRIBUTING.md.tt"
26
- template "%gem_name%/CODE_OF_CONDUCT.md.tt"
27
- template "%gem_name%/LICENSE.md.tt"
28
- template "%gem_name%/CHANGES.md.tt"
29
- end
30
-
31
- def update_readme
32
- gem_root.join("README.md").then { |path| writer.call path }
33
- end
34
- end
35
- end
36
- end
@@ -1,77 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates Ruby on Rails Engine support.
6
- class Engine < Base
7
- # :reek:TooManyStatements
8
- def run
9
- return unless runnable?
10
-
11
- install_rails
12
- create_engine
13
- create_generator_files
14
- stub_assets
15
- remove_files
16
- end
17
-
18
- private
19
-
20
- def runnable?
21
- configuration.dig :generate, :engine
22
- end
23
-
24
- def install_rails
25
- return if cli.run "command -v rails > /dev/null"
26
-
27
- cli.run "gem install rails" if cli.yes? "Would you like to install Ruby on Rails (y/n)?"
28
- end
29
-
30
- def create_engine
31
- template "#{LIB_ROOT}/%gem_path%/engine.rb.tt"
32
- cli.run "rails plugin new --skip #{configuration.dig :gem, :name} #{engine_options}"
33
- end
34
-
35
- def create_generator_files
36
- cli.empty_directory "#{generator_root}/templates"
37
- template "#{generator_root}/install/install_generator.rb.tt"
38
- template "#{generator_root}/install/USAGE.tt"
39
- template "#{generator_root}/upgrade/upgrade_generator.rb.tt"
40
- template "#{generator_root}/upgrade/USAGE.tt"
41
- end
42
-
43
- def stub_assets
44
- cli.run %(printf "%s" > "#{gem_name}/app/assets/javascripts/#{gem_path}/application.js")
45
- cli.run %(printf "%s" > "#{gem_name}/app/assets/stylesheets/#{gem_path}/application.css")
46
- end
47
-
48
- # rubocop:disable Metrics/AbcSize
49
- def remove_files
50
- cli.remove_file "#{gem_name}/app/helpers/#{gem_path}/application_helper.rb", configuration
51
- cli.remove_file "#{gem_name}/lib/#{gem_path}/version.rb", configuration
52
- cli.remove_file "#{gem_name}/MIT-LICENSE", configuration
53
- cli.remove_file "#{gem_name}/README.rdoc", configuration
54
- end
55
- # rubocop:enable Metrics/AbcSize
56
-
57
- def engine_options
58
- "--skip-git " \
59
- "--skip-bundle " \
60
- "--skip-keeps " \
61
- "--skip-turbolinks " \
62
- "--skip-spring " \
63
- "--skip-test " \
64
- "--mountable " \
65
- "--dummy-path=spec/dummy"
66
- end
67
-
68
- def generator_root
69
- "#{LIB_ROOT}/generators/%gem_path%"
70
- end
71
-
72
- def indentation
73
- " " * (configuration.dig(:gem, :path).scan("/").size + 1)
74
- end
75
- end
76
- end
77
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates default gem support.
6
- class Gem < Base
7
- def run
8
- create_binaries
9
- create_skeleton
10
- end
11
-
12
- private
13
-
14
- def create_binaries
15
- template "%gem_name%/bin/console.tt"
16
- template "%gem_name%/bin/setup.tt"
17
- cli.chmod "#{gem_name}/bin/console", 0o755
18
- cli.chmod "#{gem_name}/bin/setup", 0o755
19
- end
20
-
21
- def create_skeleton
22
- template "%gem_name%/Gemfile.tt"
23
- template "%gem_name%/%gem_name%.gemspec.tt"
24
- template "#{LIB_ROOT_GEM}.rb.tt"
25
- template "#{LIB_ROOT_GEM}/identity.rb.tt"
26
- end
27
- end
28
- end
29
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "open3"
4
- require "refinements/pathnames"
5
-
6
- module Gemsmith
7
- module Generators
8
- # Generates Git support.
9
- class Git < Base
10
- using Refinements::Pathnames
11
-
12
- def initialize cli, configuration: {}, shell: Open3
13
- super cli, configuration: configuration
14
- @shell = shell
15
- end
16
-
17
- def run
18
- create_ignore_file
19
- create_repository
20
- end
21
-
22
- private
23
-
24
- attr_reader :shell
25
-
26
- def create_ignore_file
27
- template "%gem_name%/.gitignore.tt"
28
- end
29
-
30
- def create_repository
31
- create_commit "Added gem skeleton",
32
- "Generated with [#{Identity::LABEL}](#{Identity::URL})\n" \
33
- "#{Identity::VERSION}."
34
- end
35
-
36
- def create_commit subject, body
37
- gem_root.change_dir do
38
- shell.capture3 "git init"
39
- shell.capture3 "git add ."
40
- shell.capture3 %(git commit --all --no-verify --message "#{subject}" --message "#{body}")
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates GitHub support.
6
- class GitHub < Base
7
- def run
8
- return unless configuration.dig :generate, :git_hub
9
-
10
- template "%gem_name%/.github/ISSUE_TEMPLATE.md.tt"
11
- template "%gem_name%/.github/PULL_REQUEST_TEMPLATE.md.tt"
12
- end
13
- end
14
- end
15
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates Git Lint support.
6
- class GitLint < Base
7
- def run
8
- return if configuration.dig :generate, :git_lint
9
-
10
- cli.gsub_file "#{gem_name}/Rakefile", %r(require.+git/lint.+\n), ""
11
- end
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates Guard support.
6
- class Guard < Base
7
- def run
8
- return unless configuration.dig :generate, :guard
9
-
10
- template "%gem_name%/Guardfile.tt"
11
- end
12
- end
13
- end
14
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pathname"
4
- require "pragmater"
5
-
6
- module Gemsmith
7
- module Generators
8
- # Formats pragma comments in source files.
9
- class Pragma < Base
10
- DEFAULT_COMMENTS = ["# frozen_string_literal: true"].freeze
11
-
12
- def run
13
- Pragmater::Runner.for(**attributes).call
14
- end
15
-
16
- # rubocop:disable Metrics/MethodLength
17
- def includes
18
- %W[
19
- **/*Gemfile
20
- **/*Guardfile
21
- **/*Rakefile
22
- **/*config.ru
23
- **/*bin/#{configuration.dig :gem, :name}
24
- **/*bin/bundle
25
- **/*bin/rails
26
- **/*bin/rake
27
- **/*bin/setup
28
- **/*bin/update
29
- **/*bin/yarn
30
- **/*.gemspec
31
- **/*.rake
32
- **/*.rb
33
- ]
34
- end
35
- # rubocop:enable Metrics/MethodLength
36
-
37
- private
38
-
39
- def attributes
40
- {
41
- action: :insert,
42
- root_dir: gem_root,
43
- comments: DEFAULT_COMMENTS,
44
- includes: includes
45
- }
46
- end
47
- end
48
- end
49
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "refinements/arrays"
4
-
5
- module Gemsmith
6
- module Generators
7
- # Generates Rake support.
8
- class Rake < Base
9
- using Refinements::Arrays
10
-
11
- def run
12
- template "%gem_name%/Rakefile.tt"
13
- append_code_quality_task
14
- append_default_task
15
- end
16
-
17
- def generate_code_quality_task
18
- return "" if code_quality_tasks.empty?
19
-
20
- %(\ndesc "Run code quality checks"\ntask code_quality: %i[#{code_quality_tasks}]\n)
21
- end
22
-
23
- def generate_default_task
24
- return "" if default_task.empty?
25
-
26
- %(\ntask default: %i[#{default_task}]\n)
27
- end
28
-
29
- private
30
-
31
- def rspec_task
32
- configuration.dig(:generate, :rspec) ? "spec" : ""
33
- end
34
-
35
- def bundler_audit_task
36
- configuration.dig(:generate, :bundler_audit) ? "bundle:audit" : ""
37
- end
38
-
39
- def git_lint_task
40
- configuration.dig(:generate, :git_lint) ? "git_lint" : ""
41
- end
42
-
43
- def reek_task
44
- configuration.dig(:generate, :reek) ? "reek" : ""
45
- end
46
-
47
- def rubocop_task
48
- configuration.dig(:generate, :rubocop) ? "rubocop" : ""
49
- end
50
-
51
- def code_quality_tasks
52
- [bundler_audit_task, git_lint_task, reek_task, rubocop_task].compress.join " "
53
- end
54
-
55
- def code_quality_task
56
- code_quality_tasks.empty? ? "" : "code_quality"
57
- end
58
-
59
- def default_task
60
- [code_quality_task, rspec_task].compress.join " "
61
- end
62
-
63
- def append_code_quality_task
64
- return if code_quality_task.empty?
65
-
66
- cli.append_to_file "%gem_name%/Rakefile", generate_code_quality_task
67
- end
68
-
69
- def append_default_task
70
- return if default_task.empty?
71
-
72
- cli.append_to_file "%gem_name%/Rakefile", generate_default_task
73
- end
74
- end
75
- end
76
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates Reek support.
6
- class Reek < Base
7
- def run
8
- if configuration.dig :generate, :reek
9
- template "%gem_name%/.reek.yml.tt"
10
- else
11
- cli.gsub_file "#{gem_name}/Rakefile", /require.+reek.+\n/, ""
12
- cli.gsub_file "#{gem_name}/Rakefile", /Reek.+\n/, ""
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates RSpec support.
6
- class Rspec < Base
7
- def run
8
- if configuration.dig :generate, :rspec
9
- install_templates
10
- else
11
- remove_rake_lines
12
- end
13
- end
14
-
15
- private
16
-
17
- def remove_rake_lines
18
- cli.gsub_file "#{gem_name}/Rakefile", /require.+rspec.+\n/, ""
19
- cli.gsub_file "#{gem_name}/Rakefile", /RSpec.+\n/, ""
20
- end
21
-
22
- def install_templates
23
- template "#{rspec_root}/spec_helper.rb.tt"
24
- install_rails_helper
25
- template "#{rspec_root}/support/shared_contexts/temp_dir.rb.tt"
26
- end
27
-
28
- def rspec_root
29
- "%gem_name%/spec"
30
- end
31
-
32
- def install_rails_helper
33
- return unless configuration.dig :generate, :engine
34
-
35
- template "#{rspec_root}/rails_helper.rb.tt"
36
- end
37
- end
38
- end
39
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates Rubocop support.
6
- class Rubocop < Base
7
- def run
8
- if configuration.dig :generate, :rubocop
9
- template "%gem_name%/.rubocop.yml.tt"
10
- cli.run "cd #{gem_name} && bundle exec rubocop --auto-correct > /dev/null"
11
- else
12
- cli.gsub_file "#{gem_name}/Rakefile", /require.+rubocop.+\n/, ""
13
- cli.gsub_file "#{gem_name}/Rakefile", /RuboCop.+\n/, ""
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates Ruby support.
6
- class Ruby < Base
7
- def run
8
- template "%gem_name%/.ruby-version.tt"
9
- end
10
- end
11
- end
12
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Helpers
5
- # Command Line Interface (CLI) helpers for the CLI class.
6
- module CLI
7
- module_function
8
-
9
- def print_gems gems
10
- say "Multiple versions found:\n\n"
11
-
12
- gems.each.with_index do |spec, index|
13
- say "#{index + 1}. #{spec.name} #{spec.version.version}"
14
- end
15
-
16
- say "q. Quit.\n\n"
17
- end
18
-
19
- # :reek:FeatureEnvy
20
- # :reek:TooManyStatements
21
- def pick_gem gems, name
22
- answer = ask "Enter selection:"
23
- return if answer == "q"
24
-
25
- answer = answer.to_i
26
-
27
- if (1..gems.size).cover? answer
28
- Gem::Specification.find name, gems[answer - 1].version.version
29
- else
30
- say_status :error, "Invalid option: #{answer}", :red
31
- nil
32
- end
33
- end
34
-
35
- def inspect_gem specification, method
36
- return unless specification
37
-
38
- Gem::Inspector.new.public_send method, Gem::Specification.new(specification.spec_file)
39
- rescue Versionaire::Errors::Conversion => error
40
- say_status :error, error.message, :red
41
- end
42
-
43
- # :reek:TooManyStatements
44
- def process_gem name, method
45
- specs = Gem::Specification.find_all name
46
- spec_count = specs.size
47
-
48
- if spec_count == 1
49
- inspect_gem specs.first, method
50
- elsif spec_count > 1
51
- print_gems specs
52
- inspect_gem pick_gem(specs, name), method
53
- else
54
- say_status :error, "Unable to find gem: #{name}.", :red and ""
55
- end
56
- end
57
- end
58
- end
59
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Helpers
5
- # Provides Thor CLI helper methods. These methods are necessary to resolve %% file and folder
6
- # variables and render dynamic content within the Thor ERB *templates* structure.
7
- module Template
8
- def gem_name
9
- configuration.dig :gem, :name
10
- end
11
-
12
- def gem_path
13
- configuration.dig :gem, :path
14
- end
15
-
16
- def gem_class
17
- configuration.dig :gem, :class
18
- end
19
-
20
- def rails_version
21
- configuration.dig :versions, :rails
22
- end
23
-
24
- def render_namespace &block
25
- body = capture(&block) if block
26
- concat Gem::ModuleFormatter.new(gem_class).render(body)
27
- end
28
- end
29
- end
30
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- # Gem identity information.
5
- module Identity
6
- NAME = "gemsmith"
7
- LABEL = "Gemsmith"
8
- VERSION = "15.5.0"
9
- VERSION_LABEL = "#{LABEL} #{VERSION}"
10
- URL = "https://www.alchemists.io/projects/gemsmith"
11
- end
12
- end
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/ui/shell"
4
- require "refinements/pathnames"
5
-
6
- module Gemsmith
7
- module Rake
8
- # Provides gem build functionality. Meant to be wrapped in Rake tasks.
9
- class Builder
10
- using Refinements::Pathnames
11
-
12
- def initialize root: Pathname("pkg"), shell: Bundler::UI::Shell.new, kernel: Kernel
13
- @root = root
14
- @shell = shell
15
- @kernel = kernel
16
- end
17
-
18
- def clean
19
- root.remove_tree
20
- shell.confirm "Cleaned gem artifacts."
21
- end
22
-
23
- def validate
24
- return if `git status --porcelain`.empty?
25
-
26
- shell.error "Build failed: Gem has uncommitted changes."
27
- kernel.exit 1
28
- end
29
-
30
- def build gem_spec
31
- path = gem_spec.package_path
32
-
33
- if kernel.system "gem build #{gem_spec.name}.gemspec"
34
- root.make_path
35
- Pathname(gem_spec.package_file_name).copy path
36
- shell.confirm "Built: #{path}."
37
- else
38
- shell.error "Unable to build: #{path}."
39
- end
40
- end
41
-
42
- def install gem_spec
43
- gem_name = "#{gem_spec.name} #{gem_spec.version}"
44
-
45
- if kernel.system "gem install #{gem_spec.package_path}"
46
- shell.confirm "Installed: #{gem_name}."
47
- else
48
- shell.error "Unable to install: #{gem_name}."
49
- end
50
- end
51
-
52
- private
53
-
54
- attr_reader :root, :shell, :kernel
55
- end
56
- end
57
- end