rubysmith 0.9.1 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.adoc +34 -20
  4. data/bin/rubysmith +0 -1
  5. data/lib/rubysmith/builder.rb +17 -35
  6. data/lib/rubysmith/builders/bundler.rb +7 -9
  7. data/lib/rubysmith/builders/console.rb +6 -8
  8. data/lib/rubysmith/builders/core.rb +11 -8
  9. data/lib/rubysmith/builders/documentation.rb +16 -21
  10. data/lib/rubysmith/builders/git/commit.rb +7 -11
  11. data/lib/rubysmith/builders/git/setup.rb +6 -8
  12. data/lib/rubysmith/builders/guard.rb +9 -9
  13. data/lib/rubysmith/builders/pragma.rb +8 -13
  14. data/lib/rubysmith/builders/rake.rb +7 -7
  15. data/lib/rubysmith/builders/reek.rb +6 -8
  16. data/lib/rubysmith/builders/rspec/context.rb +10 -11
  17. data/lib/rubysmith/builders/rspec/helper.rb +6 -8
  18. data/lib/rubysmith/builders/rubocop/formatter.rb +5 -7
  19. data/lib/rubysmith/builders/rubocop/setup.rb +7 -9
  20. data/lib/rubysmith/builders/setup.rb +8 -8
  21. data/lib/rubysmith/cli/actions/build.rb +42 -0
  22. data/lib/rubysmith/cli/actions/config.rb +33 -0
  23. data/lib/rubysmith/cli/configuration/content.rb +78 -0
  24. data/lib/rubysmith/cli/{defaults.yml → configuration/defaults.yml} +3 -3
  25. data/lib/rubysmith/cli/configuration/loader.rb +38 -0
  26. data/lib/rubysmith/cli/parsers/assembler.rb +11 -18
  27. data/lib/rubysmith/cli/parsers/build.rb +40 -41
  28. data/lib/rubysmith/cli/parsers/core.rb +15 -14
  29. data/lib/rubysmith/cli/parsers.rb +11 -0
  30. data/lib/rubysmith/cli/shell.rb +14 -35
  31. data/lib/rubysmith/container.rb +37 -0
  32. data/lib/rubysmith/identity.rb +2 -2
  33. data/lib/rubysmith/pathway.rb +3 -9
  34. data/lib/rubysmith/renderers/erb.rb +7 -9
  35. data/lib/rubysmith/renderers/namespace.rb +2 -4
  36. data/lib/rubysmith/templates/%project_name%/.rubocop.yml.erb +1 -1
  37. data/lib/rubysmith/templates/%project_name%/CHANGES.adoc.erb +1 -1
  38. data/lib/rubysmith/templates/%project_name%/CHANGES.md.erb +1 -1
  39. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.adoc.erb +2 -2
  40. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.md.erb +1 -1
  41. data/lib/rubysmith/templates/%project_name%/Gemfile.erb +46 -50
  42. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.adoc.erb +1 -1
  43. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.md.erb +1 -1
  44. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.adoc.erb +1 -1
  45. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.md.erb +1 -1
  46. data/lib/rubysmith/templates/%project_name%/README.adoc.erb +5 -5
  47. data/lib/rubysmith/templates/%project_name%/README.md.erb +5 -5
  48. data/lib/rubysmith/templates/%project_name%/Rakefile.erb +11 -23
  49. data/lib/rubysmith/templates/%project_name%/bin/console.erb +1 -1
  50. data/lib/rubysmith/templates/%project_name%/lib/%project_path%.rb.erb +12 -0
  51. data/lib/rubysmith/templates/%project_name%/spec/spec_helper.rb.erb +6 -4
  52. data/lib/rubysmith/templates/%project_name%/spec/support/shared_contexts/temp_dir.rb.erb +3 -3
  53. data/lib/rubysmith.rb +10 -30
  54. data.tar.gz.sig +0 -0
  55. metadata +55 -13
  56. metadata.gz.sig +0 -0
  57. data/lib/rubysmith/builders/ruby_critic.rb +0 -27
  58. data/lib/rubysmith/cli/configuration.rb +0 -30
  59. data/lib/rubysmith/cli/processors/build.rb +0 -58
  60. data/lib/rubysmith/cli/processors/config.rb +0 -35
  61. data/lib/rubysmith/realm.rb +0 -74
  62. data/lib/rubysmith/templates/%project_name%/.rubycritic.yml.erb +0 -3
  63. data/lib/rubysmith/templates/%project_name%/lib/%project_name%.rb.erb +0 -3
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-container"
4
+ require "logger"
5
+ require "pastel"
6
+
7
+ module Rubysmith
8
+ # Provides a global gem container for injection into other objects.
9
+ module Container
10
+ extend Dry::Container::Mixin
11
+
12
+ register(:configuration, memoize: true) { CLI::Configuration::Loader.call }
13
+ register(:colorizer) { Pastel.new enabled: $stdout.tty? }
14
+ 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
36
+ end
37
+ end
@@ -4,8 +4,8 @@ module Rubysmith
4
4
  module Identity
5
5
  NAME = "rubysmith"
6
6
  LABEL = "Rubysmith"
7
- VERSION = "0.9.1"
8
- VERSION_LABEL = "#{LABEL} #{VERSION}"
7
+ VERSION = "0.13.0"
8
+ VERSION_LABEL = "#{LABEL} #{VERSION}".freeze
9
9
  SUMMARY = "A command line interface for smithing Ruby projects."
10
10
  end
11
11
  end
@@ -14,17 +14,11 @@ module Rubysmith
14
14
  freeze
15
15
  end
16
16
 
17
- def with attributes
18
- self.class.new to_h.merge(attributes)
19
- end
17
+ def with(attributes) = self.class.new(to_h.merge(attributes))
20
18
 
21
- def end_path
22
- end_root.join from_parent, start_path.basename
23
- end
19
+ def end_path = end_root.join(from_parent, start_path.basename)
24
20
 
25
- def partial?
26
- start_path.basename.fnmatch? "_*"
27
- end
21
+ def partial? = start_path.basename.fnmatch?("_*")
28
22
 
29
23
  private
30
24
 
@@ -6,24 +6,22 @@ module Rubysmith
6
6
  module Renderers
7
7
  # Renders ERB templates as fully functional files.
8
8
  class ERB
9
- def initialize realm, scope: Renderers::Namespace.new(realm.project_class), client: ::ERB
10
- @realm = realm
9
+ def initialize configuration,
10
+ scope: Renderers::Namespace.new(configuration.project_class),
11
+ client: ::ERB
12
+ @configuration = configuration
11
13
  @scope = scope
12
14
  @client = client
13
15
  end
14
16
 
15
- def call content
16
- client.new(content, trim_mode: "<>", eoutvar: "@buffer").result binding
17
- end
17
+ def call(content) = client.new(content, trim_mode: "<>", eoutvar: "@buffer").result(binding)
18
18
 
19
19
  private
20
20
 
21
21
  attr_accessor :buffer
22
- attr_reader :realm, :scope, :client
22
+ attr_reader :configuration, :scope, :client
23
23
 
24
- def namespace
25
- self.buffer = scope.call yield
26
- end
24
+ def namespace = self.buffer = block_given? ? scope.call(yield) : buffer + scope.call
27
25
  end
28
26
  end
29
27
  end
@@ -14,9 +14,7 @@ module Rubysmith
14
14
  @depth = namespace.scan("::").length
15
15
  end
16
16
 
17
- def call content
18
- "#{prefix}#{body content}#{suffix.chomp}"
19
- end
17
+ def call(content = nil) = "#{prefix}#{body content}#{suffix}"
20
18
 
21
19
  private
22
20
 
@@ -30,7 +28,7 @@ module Rubysmith
30
28
 
31
29
  # :reek:FeatureEnvy
32
30
  def body content
33
- content.lstrip.split("\n").reduce "" do |snippet, line|
31
+ String(content).lstrip.split("\n").reduce "" do |snippet, line|
34
32
  next "#{snippet}\n" if line.blank?
35
33
 
36
34
  "#{snippet}#{line.gsub(/^\s{2}/, "").indent depth + 1}\n"
@@ -2,6 +2,6 @@ inherit_from:
2
2
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/main/configurations/rubocop/ruby.yml
3
3
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/main/configurations/rubocop/rake.yml
4
4
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/main/configurations/rubocop/performance.yml
5
- <% if realm.build_rspec %>
5
+ <% if configuration.build_rspec %>
6
6
  - https://raw.githubusercontent.com/bkuhlmann/code_quality/main/configurations/rubocop/rspec.yml
7
7
  <% end %>
@@ -1,5 +1,5 @@
1
1
  = Changes
2
2
 
3
- == 0.1.0 (<%= realm.now.strftime "%Y-%m-%d" %>)
3
+ == 0.1.0 (<%= configuration.now.strftime "%Y-%m-%d" %>)
4
4
 
5
5
  * Added initial implementation.
@@ -1,5 +1,5 @@
1
1
  # Changes
2
2
 
3
- ## 0.1.0 (<%= realm.now.strftime "%Y-%m-%d" %>)
3
+ ## 0.1.0 (<%= configuration.now.strftime "%Y-%m-%d" %>)
4
4
 
5
5
  - Added initial implementation.
@@ -51,8 +51,8 @@ an appointed representative at an online or offline event.
51
51
  == Enforcement
52
52
 
53
53
  Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community
54
- leaders responsible for enforcement at link:mailto:<%= realm.author_email %>?subject=Conduct[<%=
55
- realm.author_name %>].
54
+ leaders responsible for enforcement at link:mailto:<%= configuration.author_email %>?subject=Conduct[<%=
55
+ configuration.author_name %>].
56
56
 
57
57
  All complaints will be reviewed and investigated promptly and fairly.
58
58
 
@@ -51,7 +51,7 @@ an appointed representative at an online or offline event.
51
51
  ## Enforcement
52
52
 
53
53
  Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community
54
- leaders responsible for enforcement at [<%= realm.author_name %>](mailto:<%= realm.author_email
54
+ leaders responsible for enforcement at [<%= configuration.author_name %>](mailto:<%= configuration.author_email
55
55
  %>?subject=Conduct).
56
56
  All complaints will be reviewed and investigated promptly and fairly.
57
57
 
@@ -2,60 +2,56 @@ ruby File.read(".ruby-version").strip
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- <% unless realm.build_minimum %>
6
- <% if realm.build_refinements %>
7
- gem "refinements", "~> 8.0"
8
- <% end %>
5
+ <% if configuration.build_refinements %>
6
+ gem "refinements", "~> 8.0"
7
+ <% end %>
8
+ <% if configuration.build_zeitwerk %>
9
+ gem "zeitwerk", "~> 2.4"
10
+ <% end %>
9
11
 
10
- group :code_quality do
11
- <% if realm.build_bundler_audit %>
12
- gem "bundler-audit", "~> 0.7"
13
- <% end %>
14
- <% if realm.build_bundler_leak %>
15
- gem "bundler-leak", "~> 0.2"
16
- <% end %>
17
- <% if realm.build_git && realm.build_git_lint %>
18
- gem "git-lint", "~> 2.0"
19
- <% end %>
20
- <% if realm.build_reek %>
21
- gem "reek", "~> 6.0"
22
- <% end %>
23
- <% if realm.build_rubocop %>
24
- gem "rubocop", "~> 1.10"
25
- gem "rubocop-performance", "~> 1.9"
26
- gem "rubocop-rake", "~> 0.5"
27
- <% end %>
28
- <% if realm.build_rspec && realm.build_rubocop %>
29
- gem "rubocop-rspec", "~> 2.0"
30
- <% end %>
31
- <% if realm.build_ruby_critic %>
32
- gem "rubycritic", "~> 4.5", require: false
33
- <% end %>
34
- <% if realm.build_simple_cov %>
35
- gem "simplecov", "~> 0.20"
36
- <% end %>
37
- end
12
+ group :code_quality do
13
+ <% if configuration.build_bundler_leak %>
14
+ gem "bundler-leak", "~> 0.2"
15
+ <% end %>
16
+ <% if configuration.build_git && configuration.build_git_lint %>
17
+ gem "git-lint", "~> 2.0"
18
+ <% end %>
19
+ <% if configuration.build_reek %>
20
+ gem "reek", "~> 6.0"
21
+ <% end %>
22
+ <% if configuration.build_rubocop %>
23
+ gem "rubocop", "~> 1.20"
24
+ gem "rubocop-performance", "~> 1.11"
25
+ gem "rubocop-rake", "~> 0.6"
26
+ <% end %>
27
+ <% if configuration.build_rspec && configuration.build_rubocop %>
28
+ gem "rubocop-rspec", "~> 2.4"
29
+ <% end %>
30
+ <% if configuration.build_simple_cov %>
31
+ gem "simplecov", "~> 0.20"
32
+ <% end %>
33
+ end
38
34
 
35
+ <% if configuration.build_rake %>
39
36
  group :development do
40
37
  gem "rake", "~> 13.0"
41
38
  end
39
+ <% end %>
42
40
 
43
- group :test do
44
- <% if realm.build_guard %>
45
- gem "guard-rspec", "~> 4.7", require: false
46
- <% end %>
47
- <% if realm.build_rspec %>
48
- gem "rspec", "~> 3.10"
49
- <% end %>
50
- end
41
+ group :test do
42
+ <% if configuration.build_guard %>
43
+ gem "guard-rspec", "~> 4.7", require: false
44
+ <% end %>
45
+ <% if configuration.build_rspec %>
46
+ gem "rspec", "~> 3.10"
47
+ <% end %>
48
+ end
51
49
 
52
- group :tools do
53
- <% if realm.build_amazing_print %>
54
- gem "amazing_print", "~> 1.2"
55
- <% end %>
56
- <% if realm.build_pry %>
57
- gem "pry", "~> 0.13"
58
- gem "pry-byebug", "~> 3.9"
59
- <% end %>
60
- end
61
- <% end %>
50
+ group :tools do
51
+ <% if configuration.build_amazing_print %>
52
+ gem "amazing_print", "~> 1.3"
53
+ <% end %>
54
+ <% if configuration.build_debug %>
55
+ gem "debug", "~> 1.1"
56
+ <% end %>
57
+ end
@@ -150,7 +150,7 @@ additional liability.
150
150
 
151
151
  END OF TERMS AND CONDITIONS
152
152
 
153
- Copyright <%= realm.now.strftime "%Y" %> link:<%= realm.author_url %>[<%= realm.author_name %>].
153
+ Copyright <%= configuration.now.strftime "%Y" %> link:<%= configuration.author_url %>[<%= configuration.author_name %>].
154
154
 
155
155
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
156
156
  compliance with the License. You may obtain a link:https://www.apache.org/licenses/LICENSE-2.0[copy]
@@ -150,7 +150,7 @@ additional liability.
150
150
 
151
151
  END OF TERMS AND CONDITIONS
152
152
 
153
- Copyright <%= realm.now.strftime "%Y" %> [<%= realm.author_name %>](<%= realm.author_url %>).
153
+ Copyright <%= configuration.now.strftime "%Y" %> [<%= configuration.author_name %>](<%= configuration.author_url %>).
154
154
 
155
155
  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
156
156
  compliance with the License. You may obtain a [copy](https://www.apache.org/licenses/LICENSE-2.0) of
@@ -1,4 +1,4 @@
1
- Copyright <%= realm.now.strftime "%Y" %> link:<%= realm.author_url %>[<%= realm.author_name %>].
1
+ Copyright <%= configuration.now.strftime "%Y" %> link:<%= configuration.author_url %>[<%= configuration.author_name %>].
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,4 +1,4 @@
1
- Copyright <%= realm.now.strftime "%Y" %> [<%= realm.author_name %>](<%= realm.author_url %>).
1
+ Copyright <%= configuration.now.strftime "%Y" %> [<%= configuration.author_name %>](<%= configuration.author_url %>).
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -2,9 +2,9 @@
2
2
  :toclevels: 5
3
3
  :figure-caption!:
4
4
 
5
- = <%= realm.project_label %>
5
+ = <%= configuration.project_label %>
6
6
 
7
- <% if realm.build_rubocop %>
7
+ <% if configuration.build_rubocop %>
8
8
  [link=https://www.alchemists.io/projects/code_quality]
9
9
  image::https://img.shields.io/badge/code_style-alchemists-brightgreen.svg[Alchemists Style Guide]
10
10
  <% end %>
@@ -20,7 +20,7 @@ toc::[]
20
20
  . link:https://www.ruby-lang.org[Ruby].
21
21
 
22
22
  == Setup
23
- <% if realm.build_setup %>
23
+ <% if configuration.build_setup %>
24
24
 
25
25
  To set up the project, run:
26
26
 
@@ -33,7 +33,7 @@ bin/setup
33
33
  == Usage
34
34
 
35
35
  == Development
36
- <% if realm.build_console %>
36
+ <% if configuration.build_console %>
37
37
 
38
38
  You can also use the IRB console for direct access to all objects:
39
39
 
@@ -80,4 +80,4 @@ Built with link:https://www.alchemists.io/projects/rubysmith[Rubysmith].
80
80
 
81
81
  == Credits
82
82
 
83
- Engineered by link:<%= realm.author_url %>[<%= realm.author_name %>].
83
+ Engineered by link:<%= configuration.author_url %>[<%= configuration.author_name %>].
@@ -1,6 +1,6 @@
1
- # <%= realm.project_label %>
1
+ # <%= configuration.project_label %>
2
2
 
3
- <% if realm.build_rubocop %>
3
+ <% if configuration.build_rubocop %>
4
4
  [![Alchemists Style Guide](https://img.shields.io/badge/code_style-alchemists-brightgreen.svg)](https://www.alchemists.io/projects/code_quality)
5
5
  <% end %>
6
6
 
@@ -16,7 +16,7 @@
16
16
  1. [Ruby](https://www.ruby-lang.org)
17
17
 
18
18
  ## Setup
19
- <% if realm.build_setup %>
19
+ <% if configuration.build_setup %>
20
20
 
21
21
  To set up the project, run:
22
22
 
@@ -26,7 +26,7 @@ To set up the project, run:
26
26
  ## Usage
27
27
 
28
28
  ## Development
29
- <% if realm.build_console %>
29
+ <% if configuration.build_console %>
30
30
 
31
31
  You can also use the IRB console for direct access to all objects:
32
32
 
@@ -67,4 +67,4 @@ Built with [Rubysmith](https://www.alchemists.io/projects/rubysmith).
67
67
 
68
68
  ## Credits
69
69
 
70
- Engineered by [<%= realm.author_name %>](<%= realm.author_url %>).
70
+ Engineered by [<%= configuration.author_name %>](<%= configuration.author_url %>).
@@ -1,47 +1,35 @@
1
1
  require "bundler/setup"
2
2
 
3
- <% if realm.build_bundler_audit %>
4
- require "bundler/audit/task"
5
- <% end %>
6
- <% if realm.build_bundler_leak %>
3
+ <% if configuration.build_bundler_leak %>
7
4
  require "bundler/plumber/task"
8
5
  <% end %>
9
- <% if realm.build_git && realm.build_git_lint %>
6
+ <% if configuration.build_git && configuration.build_git_lint %>
10
7
  require "git/lint/rake/setup"
11
8
  <% end %>
12
- <% if realm.build_reek %>
9
+ <% if configuration.build_reek %>
13
10
  require "reek/rake/task"
14
11
  <% end %>
15
- <% if realm.build_rspec %>
12
+ <% if configuration.build_rspec %>
16
13
  require "rspec/core/rake_task"
17
14
  <% end %>
18
- <% if realm.build_rubocop %>
15
+ <% if configuration.build_rubocop %>
19
16
  require "rubocop/rake_task"
20
17
  <% end %>
21
- <% if realm.build_ruby_critic %>
22
- require "rubycritic/rake_task"
23
- <% end %>
24
18
 
25
- <% if realm.build_bundler_audit %>
26
- Bundler::Audit::Task.new
27
- <% end %>
28
- <% if realm.build_bundler_leak %>
19
+ <% if configuration.build_bundler_leak %>
29
20
  Bundler::Plumber::Task.new
30
21
  <% end %>
31
- <% if realm.build_reek %>
22
+ <% if configuration.build_reek %>
32
23
  Reek::Rake::Task.new
33
24
  <% end %>
34
- <% if realm.build_rspec %>
25
+ <% if configuration.build_rspec %>
35
26
  RSpec::Core::RakeTask.new :spec
36
27
  <% end %>
37
- <% if realm.build_rubocop %>
28
+ <% if configuration.build_rubocop %>
38
29
  RuboCop::RakeTask.new
39
30
  <% end %>
40
- <% if realm.build_ruby_critic %>
41
- RubyCritic::RakeTask.new
42
- <% end %>
43
31
 
44
32
  desc "Run code quality checks"
45
- task code_quality: %i[<% if realm.build_bundler_audit %>bundle:audit<% end %> <% if realm.build_bundler_leak %>bundle:leak<% end %> <% if realm.build_git && realm.build_git_lint %>git_lint<% end %> <% if realm.build_reek %>reek<% end %> <% if realm.build_rubocop %>rubocop<% end %> <% if realm.build_ruby_critic %>rubycritic<% end %>]
33
+ task code_quality: %i[<% if configuration.build_bundler_leak %>bundle:leak<% end %> <% if configuration.build_git && configuration.build_git_lint %>git_lint<% end %> <% if configuration.build_reek %>reek<% end %> <% if configuration.build_rubocop %>rubocop<% end %>]
46
34
 
47
- task default: %i[code_quality <% if realm.build_rspec %>spec<% end %>]
35
+ task default: %i[code_quality <% if configuration.build_rspec %>spec<% end %>]
@@ -3,7 +3,7 @@
3
3
  require "bundler/setup"
4
4
  Bundler.require :tools
5
5
 
6
- require_relative "../lib/<%= realm.project_name %>"
6
+ require_relative "../lib/<%= configuration.project_path %>"
7
7
  require "irb"
8
8
 
9
9
  IRB.start __FILE__