rubysmith 0.9.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.adoc +13 -11
  4. data/bin/rubysmith +0 -1
  5. data/lib/rubysmith/builder.rb +15 -27
  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 +9 -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/configuration/content.rb +71 -0
  22. data/lib/rubysmith/cli/{defaults.yml → configuration/defaults.yml} +2 -2
  23. data/lib/rubysmith/cli/configuration/loader.rb +35 -0
  24. data/lib/rubysmith/cli/parsers/assembler.rb +10 -15
  25. data/lib/rubysmith/cli/parsers/build.rb +16 -19
  26. data/lib/rubysmith/cli/parsers/core.rb +5 -9
  27. data/lib/rubysmith/cli/parsers.rb +11 -0
  28. data/lib/rubysmith/cli/processors/build.rb +10 -12
  29. data/lib/rubysmith/cli/processors/config.rb +3 -7
  30. data/lib/rubysmith/cli/shell.rb +9 -17
  31. data/lib/rubysmith/identity.rb +2 -2
  32. data/lib/rubysmith/pathway.rb +3 -9
  33. data/lib/rubysmith/renderers/erb.rb +7 -9
  34. data/lib/rubysmith/renderers/namespace.rb +2 -4
  35. data/lib/rubysmith/templates/%project_name%/.rubocop.yml.erb +5 -5
  36. data/lib/rubysmith/templates/%project_name%/CHANGES.adoc.erb +1 -1
  37. data/lib/rubysmith/templates/%project_name%/CHANGES.md.erb +1 -1
  38. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.adoc.erb +2 -2
  39. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.md.erb +1 -1
  40. data/lib/rubysmith/templates/%project_name%/Gemfile.erb +25 -26
  41. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.adoc.erb +1 -1
  42. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.md.erb +1 -1
  43. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.adoc.erb +1 -1
  44. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.md.erb +1 -1
  45. data/lib/rubysmith/templates/%project_name%/README.adoc.erb +5 -5
  46. data/lib/rubysmith/templates/%project_name%/README.md.erb +5 -5
  47. data/lib/rubysmith/templates/%project_name%/Rakefile.erb +11 -23
  48. data/lib/rubysmith/templates/%project_name%/bin/console.erb +1 -1
  49. data/lib/rubysmith/templates/%project_name%/lib/%project_path%.rb.erb +13 -0
  50. data/lib/rubysmith/templates/%project_name%/spec/spec_helper.rb.erb +8 -3
  51. data/lib/rubysmith/templates/%project_name%/spec/support/shared_contexts/temp_dir.rb.erb +3 -3
  52. data/lib/rubysmith.rb +9 -30
  53. data.tar.gz.sig +0 -0
  54. metadata +34 -21
  55. metadata.gz.sig +0 -0
  56. data/lib/rubysmith/builders/ruby_critic.rb +0 -27
  57. data/lib/rubysmith/cli/configuration.rb +0 -30
  58. data/lib/rubysmith/realm.rb +0 -74
  59. data/lib/rubysmith/templates/%project_name%/.rubycritic.yml.erb +0 -3
  60. data/lib/rubysmith/templates/%project_name%/lib/%project_name%.rb.erb +0 -3
@@ -1,19 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "runcom"
4
-
5
3
  module Rubysmith
6
4
  module CLI
7
5
  module Parsers
8
- CLIENT = OptionParser.new nil, 40, " "
9
- SECTIONS = [Core, Build].freeze # Order is important.
10
-
11
6
  # Assembles and parses all Command Line Interface (CLI) options.
12
7
  class Assembler
13
- def initialize client = CLIENT, sections: SECTIONS, configuration: CLI::Configuration.new
14
- @client = client
15
- @sections = sections
8
+ SECTIONS = [Core, Build].freeze # Order is important.
9
+
10
+ def initialize configuration: CLI::Configuration::Loader.call,
11
+ sections: SECTIONS,
12
+ client: CLIENT
16
13
  @options = configuration.to_h
14
+ @sections = sections
15
+ @client = client
17
16
  end
18
17
 
19
18
  def call arguments = []
@@ -22,17 +21,13 @@ module Rubysmith
22
21
  options
23
22
  end
24
23
 
25
- def to_h
26
- options
27
- end
24
+ def to_h = options
28
25
 
29
- def to_s
30
- client.to_s
31
- end
26
+ def to_s = client.to_s
32
27
 
33
28
  private
34
29
 
35
- attr_reader :client, :sections, :options
30
+ attr_reader :options, :sections, :client
36
31
  end
37
32
  end
38
33
  end
@@ -4,15 +4,12 @@ module Rubysmith
4
4
  module CLI
5
5
  module Parsers
6
6
  # Handles parsing of Command Line Interface (CLI) build options.
7
- # :reek:TooManyMethods
8
7
  class Build
9
- def self.call client:, options:
10
- new(client: client, options: options).call
11
- end
8
+ def self.call(...) = new(...).call
12
9
 
13
- def initialize client: CLIENT, options: {}
14
- @client = client
10
+ def initialize options: {}, client: CLIENT
15
11
  @options = options
12
+ @client = client
16
13
  end
17
14
 
18
15
  def call arguments = []
@@ -23,7 +20,7 @@ module Rubysmith
23
20
 
24
21
  private
25
22
 
26
- attr_reader :client, :options
23
+ attr_reader :options, :client
27
24
 
28
25
  def add_minimum
29
26
  client.on "--min", "Use minimum/no options." do |value|
@@ -37,12 +34,6 @@ module Rubysmith
37
34
  end
38
35
  end
39
36
 
40
- def add_bundler_audit
41
- client.on "--[no-]bundler-audit", "Add Bundler Audit." do |value|
42
- options[:build_bundler_audit] = value
43
- end
44
- end
45
-
46
37
  def add_bundler_leak
47
38
  client.on "--[no-]bundler-leak", "Add Bundler Leak." do |value|
48
39
  options[:build_bundler_leak] = value
@@ -85,6 +76,12 @@ module Rubysmith
85
76
  end
86
77
  end
87
78
 
79
+ def add_rake
80
+ client.on "--[no-]rake", "Add Rake." do |value|
81
+ options[:build_rake] = value
82
+ end
83
+ end
84
+
88
85
  def add_reek
89
86
  client.on "--[no-]reek", "Add Reek." do |value|
90
87
  options[:build_reek] = value
@@ -109,12 +106,6 @@ module Rubysmith
109
106
  end
110
107
  end
111
108
 
112
- def add_ruby_critic
113
- client.on "--[no-]ruby_critic", "Add RubyCritic." do |value|
114
- options[:build_ruby_critic] = value
115
- end
116
- end
117
-
118
109
  def add_setup
119
110
  client.on "--[no-]setup", "Add setup script." do |value|
120
111
  options[:build_setup] = value
@@ -126,6 +117,12 @@ module Rubysmith
126
117
  options[:build_simple_cov] = value
127
118
  end
128
119
  end
120
+
121
+ def add_zeitwerk
122
+ client.on "--[no-]zeitwerk", "Add Zeitwerk." do |value|
123
+ options[:build_zeitwerk] = value
124
+ end
125
+ end
129
126
  end
130
127
  end
131
128
  end
@@ -7,13 +7,11 @@ module Rubysmith
7
7
  module Parsers
8
8
  # Handles parsing of Command Line Interface (CLI) core options.
9
9
  class Core
10
- def self.call client:, options:
11
- new(client: client, options: options).call
12
- end
10
+ def self.call(...) = new(...).call
13
11
 
14
- def initialize client: CLIENT, options: {}
15
- @client = client
12
+ def initialize options: {}, client: CLIENT
16
13
  @options = options
14
+ @client = client
17
15
  end
18
16
 
19
17
  def call arguments = []
@@ -25,11 +23,9 @@ module Rubysmith
25
23
 
26
24
  private
27
25
 
28
- attr_reader :client, :options
26
+ attr_reader :options, :client
29
27
 
30
- def collate
31
- private_methods.sort.grep(/add_/).each { |method| __send__ method }
32
- end
28
+ def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }
33
29
 
34
30
  def add_config
35
31
  client.on "-c",
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+
5
+ module Rubysmith
6
+ module CLI
7
+ module Parsers
8
+ CLIENT = OptionParser.new nil, 40, " "
9
+ end
10
+ end
11
+ end
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "refinements/structs"
4
+
3
5
  module Rubysmith
4
6
  module CLI
5
7
  module Processors
6
8
  # Handles the Command Line Interface (CLI) for building of a project skeleton.
7
9
  class Build
10
+ using Refinements::Structs
11
+
8
12
  # Order is important.
9
13
  MINIMUM = [
10
14
  Builders::Core,
@@ -29,29 +33,23 @@ module Rubysmith
29
33
  Builders::Pragma,
30
34
  Builders::Rubocop::Setup,
31
35
  Builders::Rubocop::Formatter,
32
- Builders::RubyCritic,
33
36
  Builders::Git::Commit
34
37
  ].freeze
35
38
 
36
- def self.with_minimum
37
- new builders: MINIMUM
38
- end
39
+ def self.with_minimum = new(builders: MINIMUM)
39
40
 
40
- def initialize builders: MAXIMUM
41
+ def initialize configuration: Configuration::Loader.call, builders: MAXIMUM
42
+ @configuration = configuration
41
43
  @builders = builders
42
44
  end
43
45
 
44
- def call options
45
- Realm[**options].then { |realm| process realm }
46
- end
46
+ def call(options) = configuration.merge(**options).then { |config| process config }
47
47
 
48
48
  private
49
49
 
50
- attr_reader :builders
50
+ attr_reader :configuration, :builders
51
51
 
52
- def process realm
53
- builders.each { |builder| builder.call realm }
54
- end
52
+ def process(config) = builders.each { |builder| builder.call config }
55
53
  end
56
54
  end
57
55
  end
@@ -5,7 +5,7 @@ module Rubysmith
5
5
  module Processors
6
6
  # Handles the Command Line Interface (CLI) configuration processing.
7
7
  class Config
8
- def initialize configuration: CLI::Configuration::CLIENT, kernel: Kernel
8
+ def initialize configuration: CLI::Configuration::Loader::CLIENT, kernel: Kernel
9
9
  @configuration = configuration
10
10
  @kernel = kernel
11
11
  end
@@ -22,13 +22,9 @@ module Rubysmith
22
22
 
23
23
  attr_reader :configuration, :kernel
24
24
 
25
- def edit
26
- kernel.system "$EDITOR #{configuration.current}"
27
- end
25
+ def edit = kernel.system("$EDITOR #{configuration.current}")
28
26
 
29
- def view
30
- kernel.system "cat #{configuration.current}"
31
- end
27
+ def view = kernel.system("cat #{configuration.current}")
32
28
  end
33
29
  end
34
30
  end
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "optparse"
4
3
  require "refinements/hashes"
5
4
 
6
5
  module Rubysmith
7
6
  module CLI
8
- # Represents the Command Line Interface (CLI) for this gem.
7
+ # The main Command Line Interface (CLI) object.
9
8
  class Shell
10
9
  using Refinements::Hashes
11
10
 
@@ -24,18 +23,17 @@ module Rubysmith
24
23
  parse arguments
25
24
 
26
25
  case options
27
- in config: action, **remainder then process_config action
28
- in build_minimum: true, **remainder then process_build :build_minimum, options
29
- in build:, **remainder then process_build :build_maximum, options
30
- in version:, **remainder then puts version
31
- in help:, **remainder then usage
26
+ in config: Symbol => action then process_config action
27
+ in build_minimum: true then process_build :build_minimum, options
28
+ in build: then process_build :build_maximum, options
29
+ in version: String => version then puts version
32
30
  else usage
33
31
  end
34
32
  end
35
33
 
36
34
  private
37
35
 
38
- attr_reader :parser, :processors, :exceptions
36
+ attr_reader :parser, :processors
39
37
 
40
38
  def parse arguments = []
41
39
  parser.call arguments
@@ -43,22 +41,16 @@ module Rubysmith
43
41
  puts error.message
44
42
  end
45
43
 
46
- def process_config action
47
- processors.fetch(:config).call action
48
- end
44
+ def process_config(action) = processors.fetch(:config).call(action)
49
45
 
50
46
  def process_build kind, settings
51
47
  processors.fetch(kind).call settings.transform_keys(build: :project_name)
52
48
  .merge(now: Time.now)
53
49
  end
54
50
 
55
- def options
56
- parser.to_h
57
- end
51
+ def options = parser.to_h
58
52
 
59
- def usage
60
- puts parser.to_s
61
- end
53
+ def usage = puts(parser.to_s)
62
54
  end
63
55
  end
64
56
  end
@@ -4,8 +4,8 @@ module Rubysmith
4
4
  module Identity
5
5
  NAME = "rubysmith"
6
6
  LABEL = "Rubysmith"
7
- VERSION = "0.9.0"
8
- VERSION_LABEL = "#{LABEL} #{VERSION}"
7
+ VERSION = "0.12.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"
@@ -1,7 +1,7 @@
1
1
  inherit_from:
2
- - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/ruby.yml
3
- - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/rake.yml
4
- - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/performance.yml
5
- <% if realm.build_rspec %>
6
- - https://raw.githubusercontent.com/bkuhlmann/code_quality/master/configurations/rubocop/rspec.yml
2
+ - https://raw.githubusercontent.com/bkuhlmann/code_quality/main/configurations/rubocop/ruby.yml
3
+ - https://raw.githubusercontent.com/bkuhlmann/code_quality/main/configurations/rubocop/rake.yml
4
+ - https://raw.githubusercontent.com/bkuhlmann/code_quality/main/configurations/rubocop/performance.yml
5
+ <% if configuration.build_rspec %>
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