gemsmith 15.4.0 → 16.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/LICENSE.adoc +207 -155
  4. data/README.adoc +179 -196
  5. data/exe/gemsmith +6 -0
  6. data/gemsmith.gemspec +40 -0
  7. data/lib/gemsmith/builders/bundler.rb +34 -0
  8. data/lib/gemsmith/builders/cli.rb +86 -0
  9. data/lib/gemsmith/builders/documentation/readme.rb +37 -0
  10. data/lib/gemsmith/builders/git/commit.rb +46 -0
  11. data/lib/gemsmith/builders/git/ignore.rb +37 -0
  12. data/lib/gemsmith/builders/rspec/helper.rb +47 -0
  13. data/lib/gemsmith/builders/specification.rb +35 -0
  14. data/lib/gemsmith/cli/actions/build.rb +54 -0
  15. data/lib/gemsmith/cli/actions/config.rb +35 -0
  16. data/lib/gemsmith/cli/actions/edit.rb +39 -0
  17. data/lib/gemsmith/cli/actions/install.rb +37 -0
  18. data/lib/gemsmith/cli/actions/publish.rb +37 -0
  19. data/lib/gemsmith/cli/actions/view.rb +39 -0
  20. data/lib/gemsmith/cli/parser.rb +33 -0
  21. data/lib/gemsmith/cli/parsers/build.rb +54 -0
  22. data/lib/gemsmith/cli/parsers/core.rb +94 -0
  23. data/lib/gemsmith/cli/shell.rb +66 -0
  24. data/lib/gemsmith/configuration/enhancers/template_root.rb +20 -0
  25. data/lib/gemsmith/configuration/loader.rb +50 -0
  26. data/lib/gemsmith/container.rb +22 -0
  27. data/lib/gemsmith/gems/finder.rb +23 -0
  28. data/lib/gemsmith/gems/loader.rb +23 -0
  29. data/lib/gemsmith/gems/picker.rb +45 -0
  30. data/lib/gemsmith/gems/presenter.rb +52 -0
  31. data/lib/gemsmith/templates/%project_name%/%project_name%.gemspec.erb +50 -0
  32. data/lib/gemsmith/templates/%project_name%/exe/%project_name%.erb +5 -0
  33. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/actions/config.rb.erb +35 -0
  34. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb +31 -0
  35. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parsers/core.rb.erb +59 -0
  36. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/shell.rb.erb +40 -0
  37. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/configuration/content.rb.erb +18 -0
  38. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/configuration/defaults.yml.erb +0 -0
  39. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/configuration/loader.rb.erb +33 -0
  40. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/container.rb.erb +37 -0
  41. data/lib/gemsmith/templates/{%gem_name%/lib/%gem_path%/identity.rb.tt → %project_name%/lib/%project_path%/identity.rb.erb} +1 -1
  42. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/actions/config_spec.rb.erb +24 -0
  43. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/parser_spec.rb.erb +25 -0
  44. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/parsers/core_spec.rb.erb +53 -0
  45. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/shell_spec.rb.erb +43 -0
  46. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/configuration/content_spec.rb.erb +15 -0
  47. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/configuration/loader_spec.rb.erb +29 -0
  48. data/lib/gemsmith/templates/%project_name%/spec/support/shared_contexts/application_container.rb.erb +22 -0
  49. data/lib/gemsmith/templates/%project_name%/spec/support/shared_examples/a_parser.rb.erb +7 -0
  50. data/lib/gemsmith/tools/cleaner.rb +29 -0
  51. data/lib/gemsmith/tools/editor.rb +30 -0
  52. data/lib/gemsmith/tools/installer.rb +39 -0
  53. data/lib/gemsmith/tools/packager.rb +33 -0
  54. data/lib/gemsmith/tools/publisher.rb +34 -0
  55. data/lib/gemsmith/tools/pusher.rb +36 -0
  56. data/lib/gemsmith/tools/validator.rb +28 -0
  57. data/lib/gemsmith/tools/versioner.rb +43 -0
  58. data/lib/gemsmith/tools/viewer.rb +28 -0
  59. data/lib/gemsmith.rb +11 -32
  60. data.tar.gz.sig +0 -0
  61. metadata +101 -100
  62. metadata.gz.sig +0 -0
  63. data/bin/gemsmith +0 -9
  64. data/lib/gemsmith/authenticators/basic.rb +0 -28
  65. data/lib/gemsmith/authenticators/ruby_gems.rb +0 -41
  66. data/lib/gemsmith/cli.rb +0 -259
  67. data/lib/gemsmith/credentials.rb +0 -82
  68. data/lib/gemsmith/errors/base.rb +0 -9
  69. data/lib/gemsmith/errors/requirement_conversion.rb +0 -9
  70. data/lib/gemsmith/errors/requirement_operator.rb +0 -9
  71. data/lib/gemsmith/errors/specification.rb +0 -9
  72. data/lib/gemsmith/gem/inspector.rb +0 -30
  73. data/lib/gemsmith/gem/module_formatter.rb +0 -50
  74. data/lib/gemsmith/gem/requirement.rb +0 -55
  75. data/lib/gemsmith/gem/specification.rb +0 -74
  76. data/lib/gemsmith/generators/base.rb +0 -46
  77. data/lib/gemsmith/generators/bundler.rb +0 -19
  78. data/lib/gemsmith/generators/bundler_audit.rb +0 -15
  79. data/lib/gemsmith/generators/circle_ci.rb +0 -14
  80. data/lib/gemsmith/generators/cli.rb +0 -17
  81. data/lib/gemsmith/generators/documentation.rb +0 -36
  82. data/lib/gemsmith/generators/engine.rb +0 -77
  83. data/lib/gemsmith/generators/gem.rb +0 -29
  84. data/lib/gemsmith/generators/git.rb +0 -45
  85. data/lib/gemsmith/generators/git_hub.rb +0 -15
  86. data/lib/gemsmith/generators/git_lint.rb +0 -14
  87. data/lib/gemsmith/generators/guard.rb +0 -14
  88. data/lib/gemsmith/generators/pragma.rb +0 -49
  89. data/lib/gemsmith/generators/rake.rb +0 -81
  90. data/lib/gemsmith/generators/reek.rb +0 -17
  91. data/lib/gemsmith/generators/rspec.rb +0 -39
  92. data/lib/gemsmith/generators/rubocop.rb +0 -18
  93. data/lib/gemsmith/generators/ruby.rb +0 -12
  94. data/lib/gemsmith/helpers/cli.rb +0 -59
  95. data/lib/gemsmith/helpers/template.rb +0 -30
  96. data/lib/gemsmith/identity.rb +0 -12
  97. data/lib/gemsmith/rake/builder.rb +0 -57
  98. data/lib/gemsmith/rake/publisher.rb +0 -87
  99. data/lib/gemsmith/rake/setup.rb +0 -4
  100. data/lib/gemsmith/rake/tasks.rb +0 -83
  101. data/lib/gemsmith/templates/%gem_name%/%gem_name%.gemspec.tt +0 -44
  102. data/lib/gemsmith/templates/%gem_name%/.circleci/config.yml.tt +0 -31
  103. data/lib/gemsmith/templates/%gem_name%/.github/ISSUE_TEMPLATE.md.tt +0 -14
  104. data/lib/gemsmith/templates/%gem_name%/.github/PULL_REQUEST_TEMPLATE.md.tt +0 -11
  105. data/lib/gemsmith/templates/%gem_name%/.gitignore.tt +0 -6
  106. data/lib/gemsmith/templates/%gem_name%/.reek.yml.tt +0 -6
  107. data/lib/gemsmith/templates/%gem_name%/.rubocop.yml.tt +0 -15
  108. data/lib/gemsmith/templates/%gem_name%/.ruby-version.tt +0 -1
  109. data/lib/gemsmith/templates/%gem_name%/CHANGES.md.tt +0 -3
  110. data/lib/gemsmith/templates/%gem_name%/CODE_OF_CONDUCT.md.tt +0 -66
  111. data/lib/gemsmith/templates/%gem_name%/CONTRIBUTING.md.tt +0 -22
  112. data/lib/gemsmith/templates/%gem_name%/Gemfile.tt +0 -47
  113. data/lib/gemsmith/templates/%gem_name%/Guardfile.tt +0 -21
  114. data/lib/gemsmith/templates/%gem_name%/LICENSE.md.tt +0 -20
  115. data/lib/gemsmith/templates/%gem_name%/README.md.tt +0 -93
  116. data/lib/gemsmith/templates/%gem_name%/Rakefile.tt +0 -12
  117. data/lib/gemsmith/templates/%gem_name%/bin/%gem_name%.tt +0 -8
  118. data/lib/gemsmith/templates/%gem_name%/bin/console.tt +0 -10
  119. data/lib/gemsmith/templates/%gem_name%/bin/setup.tt +0 -8
  120. data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%/cli.rb.tt +0 -61
  121. data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%/engine.rb.tt +0 -6
  122. data/lib/gemsmith/templates/%gem_name%/lib/%gem_path%.rb.tt +0 -7
  123. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/install/USAGE.tt +0 -8
  124. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/install/install_generator.rb.tt +0 -12
  125. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/upgrade/USAGE.tt +0 -8
  126. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_path%/upgrade/upgrade_generator.rb.tt +0 -10
  127. data/lib/gemsmith/templates/%gem_name%/spec/lib/%gem_path%/cli_spec.rb.tt +0 -81
  128. data/lib/gemsmith/templates/%gem_name%/spec/rails_helper.rb.tt +0 -14
  129. data/lib/gemsmith/templates/%gem_name%/spec/spec_helper.rb.tt +0 -37
  130. data/lib/gemsmith/templates/%gem_name%/spec/support/shared_contexts/temp_dir.rb.tt +0 -9
data/lib/gemsmith/cli.rb DELETED
@@ -1,259 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "git_plus"
4
- require "thor"
5
- require "thor/actions"
6
- require "refinements/strings"
7
- require "refinements/hashes"
8
- require "runcom"
9
- require "gemsmith/helpers/cli"
10
- require "gemsmith/helpers/template"
11
- require "pathname"
12
-
13
- module Gemsmith
14
- # The Command Line Interface (CLI) for the gem.
15
- # rubocop:disable Metrics/ClassLength
16
- class CLI < Thor
17
- include Thor::Actions
18
- include Helpers::CLI
19
- include Helpers::Template
20
-
21
- using Refinements::Strings
22
- using Refinements::Hashes
23
-
24
- package_name Identity::VERSION_LABEL
25
-
26
- # Overwrites Thor's template source root.
27
- def self.source_root
28
- Pathname(__dir__).join("templates").freeze
29
- end
30
-
31
- # rubocop:disable Metrics/MethodLength
32
- def self.configuration
33
- repository = GitPlus::Repository.new
34
-
35
- Runcom::Config.new "#{Identity::NAME}/configuration.yml",
36
- defaults: {
37
- year: Time.now.year,
38
- github_user: repository.config_get("github.user"),
39
- gem: {
40
- label: "Undefined",
41
- name: "undefined",
42
- path: "undefined",
43
- class: "Undefined",
44
- platform: "Gem::Platform::RUBY",
45
- url: "",
46
- license: "MIT"
47
- },
48
- author: {
49
- name: repository.config_get("user.name"),
50
- email: repository.config_get("user.email"),
51
- url: ""
52
- },
53
- organization: {
54
- name: "",
55
- url: ""
56
- },
57
- versions: {
58
- ruby: RUBY_VERSION,
59
- rails: "6.1"
60
- },
61
- generate: {
62
- bundler_audit: true,
63
- circle_ci: false,
64
- cli: false,
65
- git_lint: true,
66
- git_hub: false,
67
- guard: true,
68
- pry: true,
69
- engine: false,
70
- reek: true,
71
- rspec: true,
72
- rubocop: true,
73
- simple_cov: true,
74
- security: false
75
- },
76
- publish: {
77
- sign: false
78
- }
79
- }
80
- end
81
- # rubocop:enable Metrics/MethodLength
82
-
83
- # rubocop:disable Metrics/MethodLength
84
- def self.generators
85
- [
86
- Generators::Gem,
87
- Generators::Documentation,
88
- Generators::Rake,
89
- Generators::CLI,
90
- Generators::Ruby,
91
- Generators::Engine,
92
- Generators::Rspec,
93
- Generators::BundlerAudit,
94
- Generators::GitLint,
95
- Generators::Reek,
96
- Generators::Guard,
97
- Generators::CircleCI,
98
- Generators::Bundler,
99
- Generators::GitHub,
100
- Generators::Pragma,
101
- Generators::Rubocop,
102
- Generators::Git
103
- ]
104
- end
105
- # rubocop:enable Metrics/MethodLength
106
-
107
- # Initialize.
108
- def initialize args = [], options = {}, config = {}
109
- super args, options, config
110
- @configuration = self.class.configuration
111
- rescue Runcom::Errors::Base => error
112
- abort error.message
113
- end
114
-
115
- desc "-g, [--generate=GEM]", "Generate new gem."
116
- map %w[-g --generate] => :generate
117
- method_option :bundler_audit,
118
- desc: "Add Bundler Audit support.",
119
- type: :boolean,
120
- default: configuration.to_h.dig(:generate, :bundler_audit)
121
- method_option :circle_ci,
122
- desc: "Add Circle CI support.",
123
- type: :boolean,
124
- default: configuration.to_h.dig(:generate, :circle_ci)
125
- method_option :cli,
126
- desc: "Add CLI support.",
127
- type: :boolean,
128
- default: configuration.to_h.dig(:generate, :cli)
129
- method_option :engine,
130
- desc: "Add Rails Engine support.",
131
- type: :boolean,
132
- default: configuration.to_h.dig(:generate, :engine)
133
- method_option :git_lint,
134
- desc: "Add Git Lint support.",
135
- type: :boolean,
136
- default: configuration.to_h.dig(:generate, :git_lint)
137
- method_option :git_hub,
138
- desc: "Add GitHub support.",
139
- type: :boolean,
140
- default: configuration.to_h.dig(:generate, :git_hub)
141
- method_option :guard,
142
- desc: "Add Guard support.",
143
- type: :boolean,
144
- default: configuration.to_h.dig(:generate, :guard)
145
- method_option :pry,
146
- desc: "Add Pry support.",
147
- type: :boolean,
148
- default: configuration.to_h.dig(:generate, :pry)
149
- method_option :reek,
150
- desc: "Add Reek support.",
151
- type: :boolean,
152
- default: configuration.to_h.dig(:generate, :reek)
153
- method_option :rspec,
154
- desc: "Add RSpec support.",
155
- type: :boolean,
156
- default: configuration.to_h.dig(:generate, :rspec)
157
- method_option :rubocop,
158
- desc: "Add Rubocop support.",
159
- type: :boolean,
160
- default: configuration.to_h.dig(:generate, :rubocop)
161
- method_option :simple_cov,
162
- desc: "Add SimpleCov support.",
163
- type: :boolean,
164
- default: configuration.to_h.dig(:generate, :simple_cov)
165
- method_option :security,
166
- desc: "Add security support.",
167
- type: :boolean,
168
- default: configuration.to_h.dig(:generate, :security)
169
- # :reek:TooManyStatements
170
- def generate name
171
- print_cli_and_rails_engine_option_error && return if options.cli? && options.engine?
172
-
173
- say_status :info, "Generating gem...", :green
174
-
175
- setup_configuration name: name, options: options.to_h
176
- self.class.generators.each { |generator| generator.run self, configuration: configuration }
177
-
178
- say_status :info, "Gem generation finished.", :green
179
- end
180
-
181
- desc "-o, [--open=GEM]", "Open a gem in default editor."
182
- map %w[-o --open] => :open
183
- def open name
184
- process_gem name, "edit"
185
- end
186
-
187
- desc "-r, [--read=GEM]", "Open a gem in default browser."
188
- map %w[-r --read] => :read
189
- def read name
190
- say_status :error, "Gem home page is not defined.", :red unless process_gem name, "visit"
191
- end
192
-
193
- desc "-c, [--config]", "Manage gem configuration."
194
- map %w[-c --config] => :config
195
- method_option :edit,
196
- aliases: "-e",
197
- desc: "Edit gem configuration.",
198
- type: :boolean,
199
- default: false
200
- method_option :info,
201
- aliases: "-i",
202
- desc: "Print gem configuration.",
203
- type: :boolean,
204
- default: false
205
- def config
206
- path = configuration.current
207
-
208
- if options.edit? then `#{ENV["EDITOR"]} #{path}`
209
- elsif options.info?
210
- path ? say(path) : say("Configuration doesn't exist.")
211
- else help :config
212
- end
213
- end
214
-
215
- desc "-v, [--version]", "Show gem version."
216
- map %w[-v --version] => :version
217
- def version
218
- say Identity::VERSION_LABEL
219
- end
220
-
221
- desc "-h, [--help=COMMAND]", "Show this message or get help for a command."
222
- map %w[-h --help] => :help
223
- def help task = nil
224
- say and super
225
- end
226
-
227
- private
228
-
229
- attr_reader :configuration
230
-
231
- # :reek:FeatureEnvy
232
- # rubocop:disable Metrics/MethodLength
233
- def setup_configuration name:, options: {}
234
- repository = GitPlus::Repository.new
235
-
236
- @configuration = configuration.to_h.merge(
237
- gem: {
238
- label: name.titleize,
239
- name: name,
240
- path: name.snakecase,
241
- class: name.camelcase,
242
- platform: "Gem::Platform::RUBY",
243
- url: %(https://github.com/#{repository.config_get "github.user"}/#{name}),
244
- license: "MIT"
245
- },
246
- generate: options.symbolize_keys
247
- )
248
- end
249
- # rubocop:enable Metrics/MethodLength
250
-
251
- def print_cli_and_rails_engine_option_error
252
- say_status :error,
253
- "Generating a gem with CLI and Rails Engine functionality is not allowed. " \
254
- "Build separate gems for improved separation of concerns and design.",
255
- :red
256
- end
257
- end
258
- # rubocop:enable Metrics/ClassLength
259
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "yaml"
4
- require "refinements/pathnames"
5
- require "gemsmith/authenticators/basic"
6
- require "gemsmith/authenticators/ruby_gems"
7
-
8
- module Gemsmith
9
- # Generates gem credentials for RubyGems and/or alternative servers.
10
- class Credentials
11
- DEFAULT_KEY = :rubygems_api_key
12
- DEFAULT_URL = "https://rubygems.org"
13
-
14
- using Refinements::Pathnames
15
-
16
- attr_reader :key, :url
17
-
18
- def self.file_path
19
- Pathname(ENV.fetch("HOME")).join ".gem", "credentials"
20
- end
21
-
22
- def self.authenticators
23
- [Authenticators::RubyGems, Authenticators::Basic]
24
- end
25
-
26
- def initialize key: DEFAULT_KEY, url: DEFAULT_URL, shell: Thor::Shell::Basic.new
27
- @key = key
28
- @url = url
29
- @shell = shell
30
- @credentials = read
31
- end
32
-
33
- def authenticator
34
- self.class
35
- .authenticators
36
- .find { |auth| auth.url.include? url }
37
- .then { |selected| selected || Authenticators::Basic }
38
- end
39
-
40
- def value
41
- String credentials[key]
42
- end
43
-
44
- def valid?
45
- exist? && !String(credentials[key]).empty?
46
- end
47
-
48
- def create
49
- write unless valid?
50
- end
51
-
52
- private
53
-
54
- attr_reader :credentials, :shell
55
-
56
- def exist?
57
- self.class.file_path.exist?
58
- end
59
-
60
- def read
61
- Hash YAML.load_file(self.class.file_path)
62
- rescue StandardError
63
- {}
64
- end
65
-
66
- def write
67
- self.class
68
- .file_path
69
- .tap { |path| path.parent.make_path }
70
- .write(YAML.dump(update))
71
- .chmod 0o600
72
- end
73
-
74
- def update
75
- login = shell.ask %(What is your "#{url}" login?)
76
- password = shell.ask %(What is your "#{url}" password?), echo: false
77
- shell.say
78
-
79
- credentials.merge key => authenticator.new(login, password).authorization
80
- end
81
- end
82
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Errors
5
- # The base error class for all gem related errors.
6
- class Base < StandardError
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Errors
5
- # Thrown when attempting to convert (cast) a primitive to a gem requirement.
6
- class RequirementConversion < Base
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Errors
5
- # Error class for gem requirement operator errors.
6
- class RequirementOperator < Base
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Errors
5
- # The error class for gem specification errors.
6
- class Specification < Base
7
- end
8
- end
9
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "open3"
4
-
5
- module Gemsmith
6
- module Gem
7
- # Provides the ability to investigate a gem in greater detail.
8
- class Inspector
9
- def self.editor
10
- ENV.fetch "EDITOR"
11
- end
12
-
13
- def initialize shell: Open3
14
- @shell = shell
15
- end
16
-
17
- def edit specification
18
- shell.capture3 self.class.editor, specification.path
19
- end
20
-
21
- def visit specification
22
- shell.capture3 "open", specification.homepage_url
23
- end
24
-
25
- private
26
-
27
- attr_reader :shell
28
- end
29
- end
30
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "refinements/strings"
4
-
5
- module Gemsmith
6
- module Gem
7
- # Formats single or multiple modules with correct, two-space indentation for templates.
8
- class ModuleFormatter
9
- using Refinements::Strings
10
-
11
- def self.indent length = 0
12
- " " * length
13
- end
14
-
15
- def initialize namespace
16
- @namespace = namespace
17
- @modules = namespace.split "::"
18
- @depth = namespace.scan("::").length
19
- end
20
-
21
- def render content
22
- "#{prefix}#{body content}#{suffix.chomp}"
23
- end
24
-
25
- private
26
-
27
- attr_reader :namespace, :modules, :depth
28
-
29
- def prefix
30
- modules.each.with_index.reduce "" do |result, (module_name, index)|
31
- result + "#{self.class.indent index}module #{module_name}\n"
32
- end
33
- end
34
-
35
- def body content
36
- content.lstrip.split("\n").reduce "" do |body, line|
37
- next "#{body}\n" if line.blank?
38
-
39
- body + "#{self.class.indent depth + 1}#{line.gsub(/^\s{2}/, "")}\n"
40
- end
41
- end
42
-
43
- def suffix
44
- modules.each.with_index.reduce "" do |result, (_, index)|
45
- result + "#{self.class.indent depth - index}end\n"
46
- end
47
- end
48
- end
49
- end
50
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "versionaire"
4
-
5
- module Gemsmith
6
- module Gem
7
- # Defines a gem requirement. This is a partial, cleaner implementation of the RubyGems
8
- # `Gem::Requirement` object.
9
- # :reek:MissingSafeMethod
10
- class Requirement
11
- def self.operators
12
- [">", ">=", "=", "!=", "<", "<=", "~>"]
13
- end
14
-
15
- def self.version_segments version
16
- String(version).split(Versionaire::Version.delimiter).map(&:to_i)
17
- end
18
-
19
- def self.for object
20
- case object
21
- when String
22
- operator, version = object.split
23
- new operator: operator, raw_version: version
24
- else
25
- fail Errors::RequirementConversion,
26
- %(Invalid string conversion. Use: "<operator> <version>".)
27
- end
28
- end
29
-
30
- attr_reader :operator, :raw_version, :version_segments, :version
31
-
32
- def initialize operator: ">=", raw_version: "0"
33
- @operator = operator
34
- @raw_version = raw_version
35
- @version_segments = self.class.version_segments raw_version
36
- @version = Versionaire::Version version_segments
37
- validate!
38
- end
39
-
40
- def to_s
41
- "#{operator} #{version}"
42
- end
43
-
44
- private
45
-
46
- def validate!
47
- operators = self.class.operators
48
- return true if operators.include? operator
49
-
50
- fail Errors::RequirementOperator,
51
- %(Invalid gem requirement operator. Use: #{operators.join ", "}.)
52
- end
53
- end
54
- end
55
- end
@@ -1,74 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pathname"
4
- require "versionaire"
5
-
6
- module Gemsmith
7
- module Gem
8
- # A Gem::Specification with additional enhancements.
9
- class Specification
10
- def self.specification
11
- ::Gem::Specification
12
- end
13
-
14
- def self.default_gem_host
15
- ::Gem::DEFAULT_HOST
16
- end
17
-
18
- def self.find name, version
19
- specification.find_by_name name, version
20
- end
21
-
22
- def self.find_all name, requirement: Gem::Requirement.new.to_s
23
- specification.find_all_by_name name, requirement
24
- end
25
-
26
- attr_reader :version
27
-
28
- def initialize file_path
29
- @file_path = file_path
30
- @spec = self.class.specification.load file_path.to_s
31
- validate
32
- @version = Versionaire::Version @spec.version.to_s
33
- end
34
-
35
- def name
36
- spec.name
37
- end
38
-
39
- def path
40
- spec.full_gem_path
41
- end
42
-
43
- def homepage_url
44
- String spec.homepage
45
- end
46
-
47
- def allowed_push_key
48
- spec.metadata.fetch "allowed_push_key", "rubygems_api_key"
49
- end
50
-
51
- def allowed_push_host
52
- spec.metadata.fetch "allowed_push_host", self.class.default_gem_host
53
- end
54
-
55
- def package_file_name
56
- "#{name}-#{version}.gem"
57
- end
58
-
59
- def package_path
60
- Pathname("pkg").join package_file_name
61
- end
62
-
63
- private
64
-
65
- attr_reader :file_path, :spec
66
-
67
- def validate
68
- return if spec.is_a? self.class.specification
69
-
70
- fail Errors::Specification, %(Unknown gem specification: "#{file_path}".)
71
- end
72
- end
73
- end
74
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "pathname"
4
-
5
- module Gemsmith
6
- module Generators
7
- # Abstract class from which all generators inherit from.
8
- class Base
9
- LIB_ROOT = Pathname("%gem_name%/lib").freeze
10
- LIB_ROOT_GEM = LIB_ROOT.join("%gem_path%").freeze
11
-
12
- def self.run cli, configuration: {}
13
- new(cli, configuration: configuration).run
14
- end
15
-
16
- def initialize cli, configuration: {}
17
- @cli = cli
18
- @configuration = configuration
19
- end
20
-
21
- def run
22
- fail NotImplementedError, "The method, #run, is not implemented yet."
23
- end
24
-
25
- protected
26
-
27
- attr_reader :cli, :configuration
28
-
29
- def gem_name
30
- configuration.dig :gem, :name
31
- end
32
-
33
- def gem_path
34
- configuration.dig :gem, :path
35
- end
36
-
37
- def gem_root
38
- Pathname(cli.destination_root).join gem_name
39
- end
40
-
41
- def template path
42
- cli.template path, configuration
43
- end
44
- end
45
- end
46
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "refinements/pathnames"
4
-
5
- module Gemsmith
6
- module Generators
7
- # Generates Bundler support.
8
- class Bundler < Base
9
- using Refinements::Pathnames
10
-
11
- def run
12
- gem_root.change_dir do
13
- cli.say_status :info, "Installing gem dependencies...", :green
14
- cli.run "bundle install"
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Gemsmith
4
- module Generators
5
- # Generates Bundler Audit support.
6
- class BundlerAudit < Base
7
- def run
8
- return if configuration.dig :generate, :bundler_audit
9
-
10
- cli.gsub_file "#{gem_name}/Rakefile", %r(require.+bundler/audit.+\n), ""
11
- cli.gsub_file "#{gem_name}/Rakefile", /Bundler::Audit.+\n/, ""
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 Circle CI support.
6
- class CircleCI < Base
7
- def run
8
- return unless configuration.dig :generate, :circle_ci
9
-
10
- template "%gem_name%/.circleci/config.yml.tt"
11
- end
12
- end
13
- end
14
- end