gemsmith 16.2.0 → 18.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/LICENSE.adoc +134 -214
  4. data/README.adoc +63 -23
  5. data/gemsmith.gemspec +8 -7
  6. data/lib/gemsmith/builders/circle_ci.rb +35 -0
  7. data/lib/gemsmith/builders/cli.rb +15 -7
  8. data/lib/gemsmith/builders/git/commit.rb +6 -5
  9. data/lib/gemsmith/cli/actions/build.rb +2 -1
  10. data/lib/gemsmith/cli/actions/config.rb +6 -7
  11. data/lib/gemsmith/cli/actions/container.rb +25 -0
  12. data/lib/gemsmith/cli/actions/edit.rb +5 -7
  13. data/lib/gemsmith/cli/actions/import.rb +11 -0
  14. data/lib/gemsmith/cli/actions/install.rb +5 -5
  15. data/lib/gemsmith/cli/actions/publish.rb +5 -5
  16. data/lib/gemsmith/cli/actions/view.rb +5 -7
  17. data/lib/gemsmith/cli/parser.rb +9 -5
  18. data/lib/gemsmith/cli/parsers/build.rb +7 -5
  19. data/lib/gemsmith/cli/parsers/core.rb +6 -5
  20. data/lib/gemsmith/cli/shell.rb +21 -40
  21. data/lib/gemsmith/container.rb +1 -1
  22. data/lib/gemsmith/import.rb +7 -0
  23. data/lib/gemsmith/templates/%project_name%/%project_name%.gemspec.erb +5 -2
  24. data/lib/gemsmith/templates/%project_name%/exe/%project_name%.erb +1 -1
  25. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/actions/config.rb.erb +6 -9
  26. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/actions/container.rb.erb +18 -0
  27. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/actions/import.rb.erb +9 -0
  28. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parser.rb.erb +9 -5
  29. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/parsers/core.rb.erb +6 -5
  30. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/shell.rb.erb +6 -15
  31. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/container.rb.erb +3 -25
  32. data/lib/gemsmith/templates/%project_name%/lib/%project_path%/import.rb.erb +5 -0
  33. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/actions/config_spec.rb.erb +4 -4
  34. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/parser_spec.rb.erb +2 -2
  35. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/parsers/core_spec.rb.erb +2 -2
  36. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/cli/shell_spec.rb.erb +17 -14
  37. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/configuration/content_spec.rb.erb +1 -1
  38. data/lib/gemsmith/templates/%project_name%/spec/lib/%project_path%/configuration/loader_spec.rb.erb +3 -3
  39. data/lib/gemsmith/templates/%project_name%/spec/support/shared_contexts/application_dependencies.rb.erb +21 -0
  40. data/lib/gemsmith/templates/%project_name%/spec/support/shared_examples/a_parser.rb.erb +1 -1
  41. data/lib/gemsmith/tools/editor.rb +2 -9
  42. data/lib/gemsmith/tools/installer.rb +5 -5
  43. data/lib/gemsmith/tools/pusher.rb +23 -5
  44. data/lib/gemsmith/tools/validator.rb +1 -10
  45. data/lib/gemsmith/tools/versioner.rb +6 -6
  46. data/lib/gemsmith/tools/viewer.rb +1 -10
  47. data.tar.gz.sig +0 -0
  48. metadata +54 -37
  49. metadata.gz.sig +0 -0
  50. data/lib/gemsmith/gems/finder.rb +0 -23
  51. data/lib/gemsmith/gems/loader.rb +0 -23
  52. data/lib/gemsmith/gems/picker.rb +0 -45
  53. data/lib/gemsmith/gems/presenter.rb +0 -52
  54. data/lib/gemsmith/templates/%project_name%/spec/support/shared_contexts/application_container.rb.erb +0 -22
@@ -4,28 +4,32 @@ require "optparse"
4
4
  module CLI
5
5
  # Assembles and parses all Command Line Interface (CLI) options.
6
6
  class Parser
7
+ include Import[:configuration]
8
+
7
9
  CLIENT = OptionParser.new nil, 40, " "
8
10
 
9
11
  # Order is important.
10
12
  SECTIONS = [Parsers::Core].freeze
11
13
 
12
- def initialize sections: SECTIONS, client: CLIENT, container: Container
14
+ def initialize sections: SECTIONS, client: CLIENT, **dependencies
15
+ super(**dependencies)
16
+
13
17
  @sections = sections
14
18
  @client = client
15
- @configuration = container[:configuration].dup
19
+ @configuration_duplicate = configuration.dup
16
20
  end
17
21
 
18
22
  def call arguments = []
19
- sections.each { |section| section.call configuration, client: }
23
+ sections.each { |section| section.call configuration_duplicate, client: }
20
24
  client.parse arguments
21
- configuration.freeze
25
+ configuration_duplicate.freeze
22
26
  end
23
27
 
24
28
  def to_s = client.to_s
25
29
 
26
30
  private
27
31
 
28
- attr_reader :sections, :client, :configuration
32
+ attr_reader :sections, :client, :configuration_duplicate
29
33
  end
30
34
  end
31
35
  <% end %>
@@ -5,16 +5,19 @@ require "refinements/structs"
5
5
  module Parsers
6
6
  # Handles parsing of Command Line Interface (CLI) core options.
7
7
  class Core
8
+ include Import[:specification]
9
+
8
10
  using Refinements::Structs
9
11
 
10
12
  def self.call(...) = new(...).call
11
13
 
12
14
  def initialize configuration = Container[:configuration],
13
15
  client: Parser::CLIENT,
14
- container: Container
16
+ **dependencies
17
+
18
+ super(**dependencies)
15
19
  @configuration = configuration
16
20
  @client = client
17
- @container = container
18
21
  end
19
22
 
20
23
  def call arguments = []
@@ -27,7 +30,7 @@ require "refinements/structs"
27
30
 
28
31
  private
29
32
 
30
- attr_reader :configuration, :client, :container
33
+ attr_reader :configuration, :client
31
34
 
32
35
  def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }
33
36
 
@@ -51,8 +54,6 @@ require "refinements/structs"
51
54
  configuration.merge! action_help: true
52
55
  end
53
56
  end
54
-
55
- def specification = container[__method__]
56
57
  end
57
58
  end
58
59
  end
@@ -2,12 +2,11 @@
2
2
  module CLI
3
3
  # The main Command Line Interface (CLI) object.
4
4
  class Shell
5
- ACTIONS = {config: Actions::Config.new}.freeze
5
+ include Actions::Import[:config, :specification, :logger]
6
6
 
7
- def initialize parser: Parser.new, actions: ACTIONS, container: Container
7
+ def initialize parser: Parser.new, **dependencies
8
+ super(**dependencies)
8
9
  @parser = parser
9
- @actions = actions
10
- @container = container
11
10
  end
12
11
 
13
12
  def call arguments = []
@@ -18,23 +17,15 @@
18
17
 
19
18
  private
20
19
 
21
- attr_reader :parser, :actions, :container
20
+ attr_reader :parser
22
21
 
23
22
  def perform configuration
24
23
  case configuration
25
- in action_config: Symbol => action then config action
24
+ in action_config: Symbol => action then config.call action
26
25
  in action_version: true then logger.info { specification.labeled_version }
27
- else usage
26
+ else logger.any { parser.to_s }
28
27
  end
29
28
  end
30
-
31
- def config(action) = actions.fetch(__method__).call(action)
32
-
33
- def usage = logger.unknown { parser.to_s }
34
-
35
- def specification = container[__method__]
36
-
37
- def logger = container[__method__]
38
29
  end
39
30
  end
40
31
  <% end %>
@@ -1,6 +1,5 @@
1
- require "dry-container"
2
- require "logger"
3
- require "pastel"
1
+ require "cogger"
2
+ require "dry/container"
4
3
  require "spek"
5
4
 
6
5
  <% namespace do %>
@@ -10,28 +9,7 @@ require "spek"
10
9
 
11
10
  register(:configuration) { Configuration::Loader.call }
12
11
  register(:specification) { Spek::Loader.call "#{__dir__}/<%= Array.new(2 + configuration.project_levels, "../").join %><%= configuration.project_name %>.gemspec" }
13
- register(:colorizer) { Pastel.new enabled: $stdout.tty? }
14
12
  register(:kernel) { Kernel }
15
-
16
- register :log_colors do
17
- {
18
- "DEBUG" => self[:colorizer].white.detach,
19
- "INFO" => self[:colorizer].green.detach,
20
- "WARN" => self[:colorizer].yellow.detach,
21
- "ERROR" => self[:colorizer].red.detach,
22
- "FATAL" => self[:colorizer].white.bold.on_red.detach,
23
- "ANY" => self[:colorizer].white.bold.detach
24
- }
25
- end
26
-
27
- register :logger do
28
- Logger.new $stdout,
29
- level: Logger.const_get(ENV.fetch("LOG_LEVEL", "INFO")),
30
- formatter: (
31
- lambda do |severity, _at, _name, message|
32
- self[:log_colors][severity].call "#{message}\n"
33
- end
34
- )
35
- end
13
+ register(:logger) { Cogger::Client.new }
36
14
  end
37
15
  <% end %>
@@ -0,0 +1,5 @@
1
+ require "auto_injector"
2
+
3
+ <% namespace do %>
4
+ Import = AutoInjector[Container]
5
+ <% end %>
@@ -1,9 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe <%= configuration.project_class %>::CLI::Actions::Config do
3
+ RSpec.describe <%= configuration.project_namespaced_class %>::CLI::Actions::Config do
4
4
  subject(:action) { described_class.new }
5
5
 
6
- include_context "with application container"
6
+ include_context "with application dependencies"
7
7
 
8
8
  describe "#call" do
9
9
  it "edits configuration" do
@@ -17,8 +17,8 @@ RSpec.describe <%= configuration.project_class %>::CLI::Actions::Config do
17
17
  end
18
18
 
19
19
  it "logs invalid configuration" do
20
- expectation = proc { action.call :bogus }
21
- expect(&expectation).to output(/Invalid configuration selection: bogus./).to_stdout
20
+ action.call :bogus
21
+ expect(logger.reread).to match(/Invalid configuration selection: bogus./)
22
22
  end
23
23
  end
24
24
  end
@@ -1,9 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe <%= configuration.project_class %>::CLI::Parser do
3
+ RSpec.describe <%= configuration.project_namespaced_class %>::CLI::Parser do
4
4
  subject(:parser) { described_class.new }
5
5
 
6
- include_context "with application container"
6
+ include_context "with application dependencies"
7
7
 
8
8
  describe "#call" do
9
9
  it "answers hash with valid option" do
@@ -1,9 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe <%= configuration.project_class %>::CLI::Parsers::Core do
3
+ RSpec.describe <%= configuration.project_namespaced_class %>::CLI::Parsers::Core do
4
4
  subject(:parser) { described_class.new configuration.dup }
5
5
 
6
- include_context "with application container"
6
+ include_context "with application dependencies"
7
7
 
8
8
  it_behaves_like "a parser"
9
9
 
@@ -1,43 +1,46 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe <%= configuration.project_class %>::CLI::Shell do
3
+ RSpec.describe <%= configuration.project_namespaced_class %>::CLI::Shell do
4
4
  using Refinements::Pathnames
5
+ using AutoInjector::Stub
5
6
 
6
- subject(:shell) { described_class.new actions: described_class::ACTIONS.merge(config:) }
7
+ subject(:shell) { described_class.new }
7
8
 
8
- include_context "with temporary directory"
9
+ include_context "with application dependencies"
9
10
 
10
- let(:config) { instance_spy <%= configuration.project_class %>::CLI::Actions::Config }
11
+ before { <%= configuration.project_namespaced_class %>::CLI::Actions::Import.stub configuration:, kernel:, logger: }
12
+
13
+ after { <%= configuration.project_namespaced_class %>::CLI::Actions::Import.unstub :configuration, :kernel, :logger }
11
14
 
12
15
  describe "#call" do
13
16
  it "edits configuration" do
14
17
  shell.call %w[--config edit]
15
- expect(config).to have_received(:call).with(:edit)
18
+ expect(kernel).to have_received(:system).with("$EDITOR ")
16
19
  end
17
20
 
18
21
  it "views configuration" do
19
22
  shell.call %w[--config view]
20
- expect(config).to have_received(:call).with(:view)
23
+ expect(kernel).to have_received(:system).with("cat ")
21
24
  end
22
25
 
23
26
  it "prints version" do
24
- expectation = proc { shell.call %w[--version] }
25
- expect(&expectation).to output(/<%= configuration.project_label %>\s\d+\.\d+\.\d+/).to_stdout
27
+ shell.call %w[--version]
28
+ expect(logger.reread).to match(/<%= configuration.project_label %>\s\d+\.\d+\.\d+/)
26
29
  end
27
30
 
28
31
  it "prints help (usage)" do
29
- expectation = proc { shell.call %w[--help] }
30
- expect(&expectation).to output(/<%= configuration.project_label %>.+USAGE.+/m).to_stdout
32
+ shell.call %w[--help]
33
+ expect(logger.reread).to match(/<%= configuration.project_label %>.+USAGE.+/m)
31
34
  end
32
35
 
33
36
  it "prints usage when no options are given" do
34
- expectation = proc { shell.call }
35
- expect(&expectation).to output(/<%= configuration.project_label %>.+USAGE.+/m).to_stdout
37
+ shell.call
38
+ expect(logger.reread).to match(/<%= configuration.project_label %>.+USAGE.+/m)
36
39
  end
37
40
 
38
41
  it "prints error with invalid option" do
39
- expectation = proc { shell.call %w[--bogus] }
40
- expect(&expectation).to output(/invalid option.+bogus/).to_stdout
42
+ shell.call %w[--bogus]
43
+ expect(logger.reread).to match(/invalid option.+bogus/)
41
44
  end
42
45
  end
43
46
  end
@@ -1,6 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe <%= configuration.project_class %>::Configuration::Content do
3
+ RSpec.describe <%= configuration.project_namespaced_class %>::Configuration::Content do
4
4
  subject(:content) { described_class.new }
5
5
 
6
6
  describe "#initialize" do
@@ -1,13 +1,13 @@
1
1
  require "spec_helper"
2
2
 
3
- RSpec.describe <%= configuration.project_class %>::Configuration::Loader do
3
+ RSpec.describe <%= configuration.project_namespaced_class %>::Configuration::Loader do
4
4
  subject(:loader) { described_class.with_defaults }
5
5
 
6
- let(:content) { <%= configuration.project_class %>::Configuration::Content.new }
6
+ let(:content) { <%= configuration.project_namespaced_class %>::Configuration::Content.new }
7
7
 
8
8
  describe ".call" do
9
9
  it "answers default configuration" do
10
- expect(described_class.call).to be_a(<%= configuration.project_class %>::Configuration::Content)
10
+ expect(described_class.call).to be_a(<%= configuration.project_namespaced_class %>::Configuration::Content)
11
11
  end
12
12
  end
13
13
 
@@ -0,0 +1,21 @@
1
+ require "dry/container/stub"
2
+ require "auto_injector/stub"
3
+
4
+ RSpec.shared_context "with application dependencies" do
5
+ using Refinements::Structs
6
+ using AutoInjector::Stub
7
+
8
+ include_context "with temporary directory"
9
+
10
+ let(:configuration) { <%= configuration.project_namespaced_class %>::Configuration::Loader.with_defaults.call }
11
+ let(:kernel) { class_spy Kernel }
12
+
13
+ let :logger do
14
+ Cogger::Client.new Logger.new(StringIO.new),
15
+ formatter: ->(_severity, _name, _at, message) { "#{message}\n" }
16
+ end
17
+
18
+ before { <%= configuration.project_namespaced_class %>::Import.stub configuration:, kernel:, logger: }
19
+
20
+ after { <%= configuration.project_namespaced_class %>::Import.unstub :configuration, :kernel, :logger }
21
+ end
@@ -1,7 +1,7 @@
1
1
  RSpec.shared_examples "a parser" do
2
2
  describe ".call" do
3
3
  it "answers configuration" do
4
- expect(described_class.call).to be_a(<%= configuration.project_class %>::Configuration::Content)
4
+ expect(described_class.call).to be_a(<%= configuration.project_namespaced_class %>::Configuration::Content)
5
5
  end
6
6
  end
7
7
  end
@@ -6,12 +6,9 @@ module Gemsmith
6
6
  module Tools
7
7
  # Edits a gem within default editor.
8
8
  class Editor
9
+ include Import[:executor, :environment]
9
10
  include Dry::Monads[:result]
10
11
 
11
- def initialize container: Container
12
- @container = container
13
- end
14
-
15
12
  def call specification
16
13
  executor.capture3(client, specification.source_path.to_s).then do |_stdout, stderr, status|
17
14
  status.success? ? Success(specification) : Failure(stderr)
@@ -20,11 +17,7 @@ module Gemsmith
20
17
 
21
18
  private
22
19
 
23
- attr_reader :container
24
-
25
- def executor = container[__method__]
26
-
27
- def client = container[:environment].fetch("EDITOR")
20
+ def client = environment.fetch("EDITOR")
28
21
  end
29
22
  end
30
23
  end
@@ -6,14 +6,16 @@ module Gemsmith
6
6
  module Tools
7
7
  # Installs a locally built gem.
8
8
  class Installer
9
+ include Import[:executor]
9
10
  include Dry::Monads[:result, :do]
10
11
 
11
12
  # Order matters.
12
13
  STEPS = [Tools::Cleaner.new, Tools::Packager.new].freeze
13
14
 
14
- def initialize steps: STEPS, container: Container
15
+ def initialize steps: STEPS, **dependencies
16
+ super(**dependencies)
17
+
15
18
  @steps = steps
16
- @container = container
17
19
  end
18
20
 
19
21
  def call specification
@@ -23,7 +25,7 @@ module Gemsmith
23
25
 
24
26
  private
25
27
 
26
- attr_reader :steps, :container
28
+ attr_reader :steps
27
29
 
28
30
  def run specification
29
31
  path = specification.package_path
@@ -32,8 +34,6 @@ module Gemsmith
32
34
  status.success? ? Success(specification) : Failure("Unable to install: #{path}.")
33
35
  end
34
36
  end
35
-
36
- def executor = container[__method__]
37
37
  end
38
38
  end
39
39
  end
@@ -7,11 +7,13 @@ module Gemsmith
7
7
  module Tools
8
8
  # Pushes a gem package to remote gem server.
9
9
  class Pusher
10
+ include Import[:executor, :logger]
10
11
  include Dry::Monads[:result]
11
12
 
12
- def initialize command: Gem::CommandManager.new, container: Container
13
+ def initialize command: Gem::CommandManager.new, **dependencies
14
+ super(**dependencies)
15
+
13
16
  @command = command
14
- @container = container
15
17
  end
16
18
 
17
19
  def call specification
@@ -23,14 +25,30 @@ module Gemsmith
23
25
 
24
26
  private
25
27
 
26
- attr_reader :command, :container
28
+ attr_reader :command
27
29
 
30
+ # :reek:TooManyStatements
28
31
  def one_time_password
29
- executor.capture3("ykman", "oath", "accounts", "code", "--single", "RubyGems")
32
+ return [] if check_yubikey.failure?
33
+
34
+ executor.capture3(check_yubikey.success, "oath", "accounts", "code", "--single", "RubyGems")
30
35
  .then { |stdout, _stderr, status| status.success? ? ["--otp", stdout.chomp] : [] }
36
+ rescue Errno::ENOENT => error
37
+ logger.warn { "Unable to obtain YubiKey One-Time Password. #{error}." }
38
+ []
31
39
  end
32
40
 
33
- def executor = container[__method__]
41
+ def check_yubikey
42
+ executor.capture3("command", "-v", "ykman")
43
+ .then do |stdout, stderr, status|
44
+ if status.success?
45
+ Success stdout.chomp
46
+ else
47
+ logger.warn { "Unable to find YubiKey Manager. #{stderr}." }
48
+ Failure()
49
+ end
50
+ end
51
+ end
34
52
  end
35
53
  end
36
54
  end
@@ -6,23 +6,14 @@ module Gemsmith
6
6
  module Tools
7
7
  # Validates whether a gem can be published or not.
8
8
  class Validator
9
+ include Import[:executor]
9
10
  include Dry::Monads[:result]
10
11
 
11
- def initialize container: Container
12
- @container = container
13
- end
14
-
15
12
  def call specification
16
13
  executor.capture3("git", "status", "--porcelain").then do |_stdout, _stderr, status|
17
14
  status.success? ? Success(specification) : Failure("Project has uncommitted changes.")
18
15
  end
19
16
  end
20
-
21
- private
22
-
23
- attr_reader :container
24
-
25
- def executor = container[__method__]
26
17
  end
27
18
  end
28
19
  end
@@ -7,14 +7,17 @@ module Gemsmith
7
7
  module Tools
8
8
  # Versions (tags) current project (local and remote).
9
9
  class Versioner
10
+ include Import[:configuration]
10
11
  include Dry::Monads[:result]
11
12
 
12
13
  def initialize client: Milestoner::Tags::Publisher.new,
13
14
  content: Milestoner::Configuration::Content,
14
- container: Container
15
+ **dependencies
16
+
17
+ super(**dependencies)
18
+
15
19
  @client = client
16
20
  @content = content
17
- @container = container
18
21
  end
19
22
 
20
23
  def call specification
@@ -26,18 +29,15 @@ module Gemsmith
26
29
 
27
30
  private
28
31
 
29
- attr_reader :client, :content, :container
32
+ attr_reader :client, :content
30
33
 
31
34
  def settings specification
32
35
  content[
33
36
  documentation_format: configuration.extensions_milestoner_documentation_format,
34
37
  prefixes: configuration.extensions_milestoner_prefixes,
35
- sign: configuration.extensions_milestoner_sign,
36
38
  version: specification.version
37
39
  ]
38
40
  end
39
-
40
- def configuration = container[__method__]
41
41
  end
42
42
  end
43
43
  end
@@ -6,23 +6,14 @@ module Gemsmith
6
6
  module Tools
7
7
  # Views a gem within default browser.
8
8
  class Viewer
9
+ include Import[:executor]
9
10
  include Dry::Monads[:result]
10
11
 
11
- def initialize container: Container
12
- @container = container
13
- end
14
-
15
12
  def call specification
16
13
  executor.capture3("open", specification.homepage_url).then do |_stdout, stderr, status|
17
14
  status.success? ? Success(specification) : Failure(stderr)
18
15
  end
19
16
  end
20
-
21
- private
22
-
23
- attr_reader :container
24
-
25
- def executor = container[__method__]
26
17
  end
27
18
  end
28
19
  end
data.tar.gz.sig CHANGED
Binary file