rubysmith 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 628bf912ecce44ded950cf18f54d54a3a8ca13430ccc300f7db53062da718716
4
- data.tar.gz: cbefec98da88d0e1b6198789805eeed82ea6b5238bee41ca9341c7d6114ed84c
3
+ metadata.gz: aa3e01ddcd6743f57757311a125d1e8ab39c44e09c1f1186a53b4a0ca6388d7d
4
+ data.tar.gz: d0725b76c5829d64fbd5e648506ae2e57adbb9882e992b84bfddaa879f166a0b
5
5
  SHA512:
6
- metadata.gz: 4b7bb2b58f60f60057c12e9f9358d720a10fe4825eefcefb8231d4998647c1d44523a550a05a2938b8d16536954ba2cb6f9fa3a4d5a484a0536f24420cb51991
7
- data.tar.gz: 315a9e28cd8231629bb17fce77051f0fb42b86c25d1fb04245437333b20171c5b5dc40b1e3cbca33cce6c611761fea3ec31493a6dad2e34c56982a598e66785d
6
+ metadata.gz: 1e14344b8a18601ef9e05ab3463491977eb81a62027dad1658a7cb1012f94f982296fe1981eea3bd90f35aa88668d3b553d3ef4bed5e77c7dddd060a8a2e444a
7
+ data.tar.gz: 7b1d999af3527fdd1a182dc2405d19b852cfb93ab8d8c70fa2f1b1e5c3261daa8548d13966d062e266911817e53e394f20442c778c59aad4f89fe4b33402380a
checksums.yaml.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -30,10 +30,10 @@ toc::[]
30
30
  * Uses link:https://www.alchemists.io/projects/pragmater[Pragmater] for Ruby source pragma directives.
31
31
  * Supports link:https://github.com/amazing-print/amazing_print[Amazing Print].
32
32
  * Supports link:https://github.com/rubymem/bundler-leak[Bundler Leak].
33
+ * Supports link:https://github.com/ruby/debug[Debug].
33
34
  * Supports link:https://git-scm.com[Git].
34
35
  * Supports link:https://www.alchemists.io/projects/git-lint[Git Lint].
35
36
  * Supports link:https://github.com/guard/guard[Guard].
36
- * Supports link:http://pryrepl.org[Pry].
37
37
  * Supports link:https://github.com/ruby/rake[Rake].
38
38
  * Supports link:https://github.com/troessner/reek[Reek].
39
39
  * Supports link:https://www.alchemists.io/projects/refinements[Refinements].
@@ -43,6 +43,7 @@ toc::[]
43
43
  * Supports link:https://github.com/rubocop-hq/rubocop-rake[Rubocop Rake].
44
44
  * Supports link:https://github.com/rubocop-hq/rubocop-rspec[Rubocop RSpec].
45
45
  * Supports link:https://github.com/simplecov-ruby/simplecov[SimpleCov].
46
+ * Supports link:https://github.com/fxn/zeitwerk[Zeitwerk].
46
47
  * Supports common settings and a structured layout for building projects.
47
48
  * Provides common documentation:
48
49
  ** README
@@ -89,12 +90,12 @@ BUILD OPTIONS:
89
90
  --[no-]amazing_print Add Amazing Print.
90
91
  --[no-]bundler-leak Add Bundler Leak.
91
92
  --[no-]console Add console script.
93
+ --[no-]debug Add Debug.
92
94
  --[no-]documentation Add documentation.
93
95
  --[no-]git Add Git.
94
96
  --[no-]git-lint Add Git Lint.
95
97
  --[no-]guard Add Guard.
96
98
  --min Use minimum/no options.
97
- --[no-]pry Add Pry.
98
99
  --[no-]rake Add Rake.
99
100
  --[no-]reek Add Reek.
100
101
  --[no-]refinements Add Refinements.
@@ -120,12 +121,12 @@ to disable specific options, you can use the `--no-*` prefix. Example:
120
121
 
121
122
  [source,bash]
122
123
  ----
123
- rubysmith --build demo --no-pry --no-guard
124
+ rubysmith --build demo --no-debug --no-guard
124
125
  ----
125
126
 
126
- With the above example, both Pry and Guard support would have been disabled when building the `demo`
127
- project. Taking this a step further, you can also use the `--min` option to generate a project with
128
- bare minimum of options. Example:
127
+ With the above example, both Debug and Guard support would have been disabled when building the
128
+ `demo` project. Taking this a step further, you can also use the `--min` option to generate a
129
+ project with bare minimum of options. Example:
129
130
 
130
131
  [source,bash]
131
132
  ----
@@ -136,8 +137,19 @@ The above is essentially the same as building with _all_ options disabled. This
136
137
  situations where you need to quickly script something up for sharing with others yet still want to
137
138
  avoid using a Bundler Inline script so gem dependencies are not installed each time the code is run.
138
139
 
139
- To have specific options enabled/disabled _every time_ you build a new Ruby project, you can edit
140
- your global configuration for making these settings permanent (see below for details).
140
+ As shown earlier, you can combine options but the order options can be handy in certain situations
141
+ especially when used with the minimum build option. Example:
142
+
143
+ [source,bash]
144
+ ----
145
+ rubysmith --build demo --min --zeitwerk
146
+ ----
147
+
148
+ The above will disable _all_ options except for Zeitwerk which will be enabled in this situation.
149
+ This can be a handy way to build a new project with all options disabled with only a few select
150
+ options enabled. To have specific options enabled/disabled _every time_ you build a new Ruby
151
+ project, you can edit your global configuration for making these settings permanent (see below for
152
+ details).
141
153
 
142
154
  === Configuration
143
155
 
@@ -165,12 +177,12 @@ The default configuration is as follows:
165
177
  :amazing_print: true
166
178
  :bundler_leak: true
167
179
  :console: true
180
+ :debug: true
168
181
  :documentation: true
169
182
  :git: true
170
183
  :git_lint: true
171
184
  :guard: true
172
185
  :minimum: false
173
- :pry: true
174
186
  :rake: true
175
187
  :reek: true
176
188
  :refinements: true
@@ -10,20 +10,14 @@ module Rubysmith
10
10
  class Builder
11
11
  using Refinements::Pathnames
12
12
 
13
- LOGGER = Logger.new(STDOUT, formatter: ->(_severity, _at, _program, message) { "#{message}\n" })
14
-
15
- HELPERS = {
16
- inserter: Text::Inserter,
17
- renderer: Renderers::ERB,
18
- kernel: Open3,
19
- logger: LOGGER
20
- }.freeze
13
+ HELPERS = {inserter: Text::Inserter, renderer: Renderers::ERB, kernel: Open3}.freeze
21
14
 
22
15
  def self.call(...) = new(...)
23
16
 
24
- def initialize configuration, helpers: HELPERS
17
+ def initialize configuration, helpers: HELPERS, container: Container
25
18
  @configuration = configuration
26
19
  @helpers = helpers
20
+ @container = container
27
21
  end
28
22
 
29
23
  def append content
@@ -100,7 +94,7 @@ module Rubysmith
100
94
 
101
95
  private
102
96
 
103
- attr_reader :configuration, :helpers
97
+ attr_reader :configuration, :helpers, :container
104
98
 
105
99
  def execute *command
106
100
  kernel.capture2e(*command).then do |result, status|
@@ -114,9 +108,9 @@ module Rubysmith
114
108
 
115
109
  def kernel = helpers.fetch(__method__)
116
110
 
117
- def logger = helpers.fetch(__method__)
111
+ def logger = container[__method__]
118
112
 
119
- def relative_build_path = build_path.relative_path_from(configuration.build_root)
113
+ def relative_build_path = build_path.relative_path_from(configuration.target_root)
120
114
 
121
115
  def build_path
122
116
  pathway.end_path
@@ -14,7 +14,9 @@ module Rubysmith
14
14
  def call
15
15
  builder.call(configuration.with(template_path: "%project_name%/lib/%project_path%.rb.erb"))
16
16
  .render
17
- .replace(/ (?!(module|end))/, "")
17
+ .replace(" require", "require")
18
+ .replace(/ (?=(Zeit|\.tap|\.setup))/, "")
19
+ .replace("\n \n", "\n\n")
18
20
 
19
21
  builder.call(configuration.with(template_path: "%project_name%/.ruby-version.erb")).render
20
22
  nil
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module CLI
5
+ module Actions
6
+ # Handles the build action.
7
+ class Build
8
+ # Order is important.
9
+ BUILDERS = [
10
+ Builders::Core,
11
+ Builders::Documentation,
12
+ Builders::Git::Setup,
13
+ Builders::Bundler,
14
+ Builders::Rake,
15
+ Builders::Console,
16
+ Builders::Setup,
17
+ Builders::Guard,
18
+ Builders::Reek,
19
+ Builders::RSpec::Context,
20
+ Builders::RSpec::Helper,
21
+ Builders::Pragma,
22
+ Builders::Rubocop::Setup,
23
+ Builders::Rubocop::Formatter,
24
+ Builders::Git::Commit
25
+ ].freeze
26
+
27
+ def initialize builders: BUILDERS, container: Container
28
+ @builders = builders
29
+ @container = container
30
+ end
31
+
32
+ def call = builders.each { |builder| builder.call configuration }
33
+
34
+ private
35
+
36
+ attr_reader :builders, :container
37
+
38
+ def configuration = container[__method__]
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module CLI
5
+ module Actions
6
+ # Handles the config action.
7
+ class Config
8
+ def initialize client: CLI::Configuration::Loader::CLIENT, container: Container
9
+ @client = client
10
+ @container = container
11
+ end
12
+
13
+ def call selection
14
+ case selection
15
+ when :edit then edit
16
+ when :view then view
17
+ else fail StandardError, "Invalid configuration selection: #{selection}."
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :client, :container
24
+
25
+ def edit = kernel.system("$EDITOR #{client.current}")
26
+
27
+ def view = kernel.system("cat #{client.current}")
28
+
29
+ def kernel = container[__method__]
30
+ end
31
+ end
32
+ end
33
+ end
@@ -8,26 +8,22 @@ module Rubysmith
8
8
  module Configuration
9
9
  # Defines the common configuration content for use throughout the gem.
10
10
  Content = Struct.new(
11
- :config,
12
- :template_root,
13
- :template_path,
14
- :build_root,
15
- :project_name,
16
- :author_name,
11
+ :action_build,
12
+ :action_config,
13
+ :action_help,
14
+ :action_version,
17
15
  :author_email,
16
+ :author_name,
18
17
  :author_url,
19
- :now,
20
- :documentation_format,
21
- :documentation_license,
22
- :build_minimum,
23
18
  :build_amazing_print,
24
19
  :build_bundler_leak,
25
20
  :build_console,
21
+ :build_debug,
26
22
  :build_documentation,
27
23
  :build_git,
28
24
  :build_git_lint,
29
25
  :build_guard,
30
- :build_pry,
26
+ :build_minimum,
31
27
  :build_rake,
32
28
  :build_reek,
33
29
  :build_refinements,
@@ -38,8 +34,13 @@ module Rubysmith
38
34
  :build_zeitwerk,
39
35
  :builders_pragmater_comments,
40
36
  :builders_pragmater_includes,
41
- :version,
42
- :help,
37
+ :documentation_format,
38
+ :documentation_license,
39
+ :now,
40
+ :project_name,
41
+ :target_root,
42
+ :template_path,
43
+ :template_root,
43
44
  keyword_init: true
44
45
  ) do
45
46
  using Refinements::Strings
@@ -48,22 +49,28 @@ module Rubysmith
48
49
  super
49
50
 
50
51
  self[:template_root] ||= Pathname(__dir__).join("../../templates").expand_path
51
- self[:build_root] ||= Pathname.pwd
52
- freeze
52
+ self[:target_root] ||= Pathname.pwd
53
53
  end
54
54
 
55
55
  def with(attributes) = self.class.new(to_h.merge(attributes))
56
56
 
57
+ def minimize
58
+ to_h.except(:build_minimum)
59
+ .select { |key, _value| key.start_with? "build_" }
60
+ .each { |key, _value| self[key] = false }
61
+ .then { self }
62
+ end
63
+
57
64
  def project_label = project_name.titleize
58
65
 
59
66
  def project_class = project_name.camelcase
60
67
 
61
- def project_root = build_root.join(project_name)
68
+ def project_root = target_root.join(project_name)
62
69
 
63
70
  def project_path = project_name.snakecase
64
71
 
65
72
  def to_pathway
66
- Pathway[start_root: template_root, start_path: template_path, end_root: build_root]
73
+ Pathway[start_root: template_root, start_path: template_path, end_root: target_root]
67
74
  end
68
75
  end
69
76
  end
@@ -11,12 +11,12 @@
11
11
  :amazing_print: true
12
12
  :bundler_leak: true
13
13
  :console: true
14
+ :debug: true
14
15
  :documentation: true
15
16
  :git: true
16
17
  :git_lint: true
17
18
  :guard: true
18
19
  :minimum: false
19
- :pry: true
20
20
  :rake: true
21
21
  :reek: true
22
22
  :refinements: true
@@ -17,18 +17,21 @@ module Rubysmith
17
17
  DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze
18
18
  CLIENT = Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: DEFAULTS
19
19
 
20
- def self.call = new.call
20
+ def self.call(...) = new(...).call
21
21
 
22
- def initialize content: Content.new, client: CLIENT
22
+ def self.with_defaults(now: Time.now) = new(now: now, client: DEFAULTS)
23
+
24
+ def initialize now: Time.now, content: Content.new, client: CLIENT
25
+ @now = now
23
26
  @content = content
24
27
  @client = client
25
28
  end
26
29
 
27
- def call = content.merge(**client.to_h.flatten_keys)
30
+ def call = content.merge(**client.to_h.flatten_keys, now: now)
28
31
 
29
32
  private
30
33
 
31
- attr_reader :content, :client
34
+ attr_reader :now, :content, :client
32
35
  end
33
36
  end
34
37
  end
@@ -7,27 +7,25 @@ module Rubysmith
7
7
  class Assembler
8
8
  SECTIONS = [Core, Build].freeze # Order is important.
9
9
 
10
- def initialize configuration: CLI::Configuration::Loader.call,
11
- sections: SECTIONS,
12
- client: CLIENT
13
- @options = configuration.to_h
10
+ def initialize sections: SECTIONS, client: CLIENT, container: Container
14
11
  @sections = sections
15
12
  @client = client
13
+ @container = container
16
14
  end
17
15
 
18
16
  def call arguments = []
19
- sections.each { |parser| parser.call client: client, options: options }
17
+ sections.each { |parser| parser.call client: client }
20
18
  client.parse! arguments
21
- options
19
+ configuration
22
20
  end
23
21
 
24
- def to_h = options
25
-
26
22
  def to_s = client.to_s
27
23
 
28
24
  private
29
25
 
30
- attr_reader :options, :sections, :client
26
+ attr_reader :sections, :client, :container
27
+
28
+ def configuration = container[__method__]
31
29
  end
32
30
  end
33
31
  end
@@ -7,9 +7,9 @@ module Rubysmith
7
7
  class Build
8
8
  def self.call(...) = new(...).call
9
9
 
10
- def initialize options: {}, client: CLIENT
11
- @options = options
10
+ def initialize client: CLIENT, container: Container
12
11
  @client = client
12
+ @container = container
13
13
  end
14
14
 
15
15
  def call arguments = []
@@ -20,109 +20,111 @@ module Rubysmith
20
20
 
21
21
  private
22
22
 
23
- attr_reader :options, :client
24
-
25
- def add_minimum
26
- client.on "--min", "Use minimum/no options." do |value|
27
- options[:build_minimum] = value
28
- end
29
- end
23
+ attr_reader :client, :container
30
24
 
31
25
  def add_amazing_print
32
26
  client.on "--[no-]amazing_print", "Add Amazing Print." do |value|
33
- options[:build_amazing_print] = value
27
+ configuration.build_amazing_print = value
34
28
  end
35
29
  end
36
30
 
37
31
  def add_bundler_leak
38
32
  client.on "--[no-]bundler-leak", "Add Bundler Leak." do |value|
39
- options[:build_bundler_leak] = value
33
+ configuration.build_bundler_leak = value
40
34
  end
41
35
  end
42
36
 
43
37
  def add_console
44
38
  client.on "--[no-]console", "Add console script." do |value|
45
- options[:build_console] = value
39
+ configuration.build_console = value
40
+ end
41
+ end
42
+
43
+ def add_debug
44
+ client.on "--[no-]debug", "Add Debug." do |value|
45
+ configuration.build_debug = value
46
46
  end
47
47
  end
48
48
 
49
49
  def add_documentation
50
50
  client.on "--[no-]documentation", "Add documentation." do |value|
51
- options[:build_documentation] = value
51
+ configuration.build_documentation = value
52
52
  end
53
53
  end
54
54
 
55
55
  def add_git
56
56
  client.on "--[no-]git", "Add Git." do |value|
57
- options[:build_git] = value
57
+ configuration.build_git = value
58
58
  end
59
59
  end
60
60
 
61
61
  def add_git_lint
62
62
  client.on "--[no-]git-lint", "Add Git Lint." do |value|
63
- options[:build_git_lint] = value
63
+ configuration.build_git_lint = value
64
64
  end
65
65
  end
66
66
 
67
67
  def add_guard
68
68
  client.on "--[no-]guard", "Add Guard." do |value|
69
- options[:build_guard] = value
69
+ configuration.build_guard = value
70
70
  end
71
71
  end
72
72
 
73
- def add_pry
74
- client.on "--[no-]pry", "Add Pry." do |value|
75
- options[:build_pry] = value
73
+ def add_minimum
74
+ client.on "--min", "Use minimum/no options." do |value|
75
+ configuration.minimize.build_minimum = value
76
76
  end
77
77
  end
78
78
 
79
79
  def add_rake
80
80
  client.on "--[no-]rake", "Add Rake." do |value|
81
- options[:build_rake] = value
81
+ configuration.build_rake = value
82
82
  end
83
83
  end
84
84
 
85
85
  def add_reek
86
86
  client.on "--[no-]reek", "Add Reek." do |value|
87
- options[:build_reek] = value
87
+ configuration.build_reek = value
88
88
  end
89
89
  end
90
90
 
91
91
  def add_refinements
92
92
  client.on "--[no-]refinements", "Add Refinements." do |value|
93
- options[:build_refinements] = value
93
+ configuration.build_refinements = value
94
94
  end
95
95
  end
96
96
 
97
97
  def add_rspec
98
98
  client.on "--[no-]rspec", "Add RSpec." do |value|
99
- options[:build_rspec] = value
99
+ configuration.build_rspec = value
100
100
  end
101
101
  end
102
102
 
103
103
  def add_rubocop
104
104
  client.on "--[no-]rubocop", "Add Rubocop." do |value|
105
- options[:build_rubocop] = value
105
+ configuration.build_rubocop = value
106
106
  end
107
107
  end
108
108
 
109
109
  def add_setup
110
110
  client.on "--[no-]setup", "Add setup script." do |value|
111
- options[:build_setup] = value
111
+ configuration.build_setup = value
112
112
  end
113
113
  end
114
114
 
115
115
  def add_simple_cov
116
116
  client.on "--[no-]simple_cov", "Add SimpleCov." do |value|
117
- options[:build_simple_cov] = value
117
+ configuration.build_simple_cov = value
118
118
  end
119
119
  end
120
120
 
121
121
  def add_zeitwerk
122
122
  client.on "--[no-]zeitwerk", "Add Zeitwerk." do |value|
123
- options[:build_zeitwerk] = value
123
+ configuration.build_zeitwerk = value
124
124
  end
125
125
  end
126
+
127
+ def configuration = container[__method__]
126
128
  end
127
129
  end
128
130
  end
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rubysmith/identity"
4
+ require "refinements/structs"
4
5
 
5
6
  module Rubysmith
6
7
  module CLI
7
8
  module Parsers
8
9
  # Handles parsing of Command Line Interface (CLI) core options.
9
10
  class Core
11
+ using Refinements::Structs
12
+
10
13
  def self.call(...) = new(...).call
11
14
 
12
- def initialize options: {}, client: CLIENT
13
- @options = options
15
+ def initialize client: CLIENT, container: Container
14
16
  @client = client
17
+ @container = container
15
18
  end
16
19
 
17
20
  def call arguments = []
@@ -23,7 +26,7 @@ module Rubysmith
23
26
 
24
27
  private
25
28
 
26
- attr_reader :options, :client
29
+ attr_reader :client, :container
27
30
 
28
31
  def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }
29
32
 
@@ -32,27 +35,29 @@ module Rubysmith
32
35
  "--config ACTION",
33
36
  %i[edit view],
34
37
  "Manage gem configuration: edit or view." do |action|
35
- options[:config] = action
38
+ configuration.action_config = action
36
39
  end
37
40
  end
38
41
 
39
42
  def add_build
40
- client.on "-b", "--build NAME [options]", "Build new project." do |value|
41
- options[:build] = value
43
+ client.on "-b", "--build NAME [options]", "Build new project." do |name|
44
+ configuration.merge! action_build: true, project_name: name
42
45
  end
43
46
  end
44
47
 
45
48
  def add_version
46
49
  client.on "-v", "--version", "Show gem version." do
47
- options[:version] = Identity::VERSION_LABEL
50
+ configuration.action_version = Identity::VERSION_LABEL
48
51
  end
49
52
  end
50
53
 
51
54
  def add_help
52
55
  client.on "-h", "--help", "Show this message." do
53
- options[:help] = true
56
+ configuration.action_help = true
54
57
  end
55
58
  end
59
+
60
+ def configuration = container[__method__]
56
61
  end
57
62
  end
58
63
  end
@@ -1,39 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "refinements/hashes"
4
-
5
3
  module Rubysmith
6
4
  module CLI
7
5
  # The main Command Line Interface (CLI) object.
8
6
  class Shell
9
- using Refinements::Hashes
10
-
11
- PROCESSORS = {
12
- config: Processors::Config.new,
13
- build_minimum: Processors::Build.with_minimum,
14
- build_maximum: Processors::Build.new
15
- }.freeze
7
+ ACTIONS = {config: Actions::Config.new, build: Actions::Build.new}.freeze
16
8
 
17
- def initialize parser: Parsers::Assembler.new, processors: PROCESSORS
9
+ def initialize parser: Parsers::Assembler.new, actions: ACTIONS, container: Container
18
10
  @parser = parser
19
- @processors = processors
11
+ @actions = actions
12
+ @container = container
20
13
  end
21
14
 
22
15
  def call arguments = []
23
- parse arguments
24
-
25
- case options
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
16
+ case parse arguments
17
+ in action_config: Symbol => action then config action
18
+ in action_build: true then build
19
+ in action_version: String => version then puts version
30
20
  else usage
31
21
  end
32
22
  end
33
23
 
34
24
  private
35
25
 
36
- attr_reader :parser, :processors
26
+ attr_reader :parser, :actions, :container
37
27
 
38
28
  def parse arguments = []
39
29
  parser.call arguments
@@ -41,16 +31,13 @@ module Rubysmith
41
31
  puts error.message
42
32
  end
43
33
 
44
- def process_config(action) = processors.fetch(:config).call(action)
34
+ def config(action) = actions.fetch(__method__).call(action)
45
35
 
46
- def process_build kind, settings
47
- processors.fetch(kind).call settings.transform_keys(build: :project_name)
48
- .merge(now: Time.now)
49
- end
36
+ def build = actions.fetch(__method__).call
50
37
 
51
- def options = parser.to_h
38
+ def usage = logger.unknown(parser.to_s)
52
39
 
53
- def usage = puts(parser.to_s)
40
+ def logger = container[__method__]
54
41
  end
55
42
  end
56
43
  end
@@ -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,7 +4,7 @@ module Rubysmith
4
4
  module Identity
5
5
  NAME = "rubysmith"
6
6
  LABEL = "Rubysmith"
7
- VERSION = "0.12.0"
7
+ VERSION = "0.13.0"
8
8
  VERSION_LABEL = "#{LABEL} #{VERSION}".freeze
9
9
  SUMMARY = "A command line interface for smithing Ruby projects."
10
10
  end
@@ -2,59 +2,56 @@ ruby File.read(".ruby-version").strip
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- <% unless configuration.build_minimum %>
6
- <% if configuration.build_refinements %>
7
- gem "refinements", "~> 8.0"
5
+ <% if configuration.build_refinements %>
6
+ gem "refinements", "~> 8.0"
7
+ <% end %>
8
+ <% if configuration.build_zeitwerk %>
9
+ gem "zeitwerk", "~> 2.4"
10
+ <% end %>
11
+
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"
8
18
  <% end %>
9
- <% if configuration.build_zeitwerk %>
10
- gem "zeitwerk", "~> 2.4"
19
+ <% if configuration.build_reek %>
20
+ gem "reek", "~> 6.0"
11
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
12
34
 
13
- group :code_quality do
14
- <% if configuration.build_bundler_leak %>
15
- gem "bundler-leak", "~> 0.2"
16
- <% end %>
17
- <% if configuration.build_git && configuration.build_git_lint %>
18
- gem "git-lint", "~> 2.0"
19
- <% end %>
20
- <% if configuration.build_reek %>
21
- gem "reek", "~> 6.0"
22
- <% end %>
23
- <% if configuration.build_rubocop %>
24
- gem "rubocop", "~> 1.20"
25
- gem "rubocop-performance", "~> 1.11"
26
- gem "rubocop-rake", "~> 0.6"
27
- <% end %>
28
- <% if configuration.build_rspec && configuration.build_rubocop %>
29
- gem "rubocop-rspec", "~> 2.4"
30
- <% end %>
31
- <% if configuration.build_simple_cov %>
32
- gem "simplecov", "~> 0.20"
33
- <% end %>
35
+ <% if configuration.build_rake %>
36
+ group :development do
37
+ gem "rake", "~> 13.0"
34
38
  end
39
+ <% end %>
35
40
 
36
- <% if configuration.build_rake %>
37
- group :development do
38
- gem "rake", "~> 13.0"
39
- end
41
+ group :test do
42
+ <% if configuration.build_guard %>
43
+ gem "guard-rspec", "~> 4.7", require: false
40
44
  <% end %>
45
+ <% if configuration.build_rspec %>
46
+ gem "rspec", "~> 3.10"
47
+ <% end %>
48
+ end
41
49
 
42
- group :test do
43
- <% if configuration.build_guard %>
44
- gem "guard-rspec", "~> 4.7", require: false
45
- <% end %>
46
- <% if configuration.build_rspec %>
47
- gem "rspec", "~> 3.10"
48
- <% end %>
49
- end
50
-
51
- group :tools do
52
- <% if configuration.build_amazing_print %>
53
- gem "amazing_print", "~> 1.3"
54
- <% end %>
55
- <% if configuration.build_pry %>
56
- gem "pry", "~> 0.13"
57
- gem "pry-byebug", "~> 3.9"
58
- <% end %>
59
- end
60
- <% 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
@@ -1,12 +1,11 @@
1
1
  <% if configuration.build_zeitwerk %>
2
2
  require "zeitwerk"
3
3
  <% if configuration.project_path.include? "/" %>
4
- loader = Zeitwerk::Loader.new
5
- loader.push_dir "#{__dir__}/.."
6
- loader.setup
4
+ Zeitwerk::Loader.new
5
+ .tap { |loader| loader.push_dir "#{__dir__}/.." }
6
+ .setup
7
7
  <% else %>
8
- loader = Zeitwerk::Loader.for_gem
9
- loader.setup
8
+ Zeitwerk::Loader.for_gem.setup
10
9
  <% end %>
11
10
  <% end %>
12
11
  # Main namespace.
data/lib/rubysmith.rb CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  require "zeitwerk"
4
4
 
5
- loader = Zeitwerk::Loader.for_gem
6
- loader.inflector.inflect "cli" => "CLI", "erb" => "ERB", "rspec" => "RSpec"
7
- loader.setup
5
+ Zeitwerk::Loader.for_gem.then do |loader|
6
+ loader.inflector.inflect "cli" => "CLI", "erb" => "ERB", "rspec" => "RSpec"
7
+ loader.setup
8
+ end
8
9
 
9
10
  # Main namespace.
10
11
  module Rubysmith
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysmith
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,8 +28,36 @@ cert_chain:
28
28
  lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
29
29
  W2A=
30
30
  -----END CERTIFICATE-----
31
- date: 2021-09-06 00:00:00.000000000 Z
31
+ date: 2021-09-16 00:00:00.000000000 Z
32
32
  dependencies:
33
+ - !ruby/object:Gem::Dependency
34
+ name: dry-container
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.9'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.9'
47
+ - !ruby/object:Gem::Dependency
48
+ name: pastel
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.8'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.8'
33
61
  - !ruby/object:Gem::Dependency
34
62
  name: pragmater
35
63
  requirement: !ruby/object:Gem::Requirement
@@ -130,6 +158,8 @@ files:
130
158
  - lib/rubysmith/builders/rubocop/formatter.rb
131
159
  - lib/rubysmith/builders/rubocop/setup.rb
132
160
  - lib/rubysmith/builders/setup.rb
161
+ - lib/rubysmith/cli/actions/build.rb
162
+ - lib/rubysmith/cli/actions/config.rb
133
163
  - lib/rubysmith/cli/configuration/content.rb
134
164
  - lib/rubysmith/cli/configuration/defaults.yml
135
165
  - lib/rubysmith/cli/configuration/loader.rb
@@ -137,9 +167,8 @@ files:
137
167
  - lib/rubysmith/cli/parsers/assembler.rb
138
168
  - lib/rubysmith/cli/parsers/build.rb
139
169
  - lib/rubysmith/cli/parsers/core.rb
140
- - lib/rubysmith/cli/processors/build.rb
141
- - lib/rubysmith/cli/processors/config.rb
142
170
  - lib/rubysmith/cli/shell.rb
171
+ - lib/rubysmith/container.rb
143
172
  - lib/rubysmith/identity.rb
144
173
  - lib/rubysmith/pathway.rb
145
174
  - lib/rubysmith/renderers/erb.rb
metadata.gz.sig CHANGED
Binary file
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "refinements/structs"
4
-
5
- module Rubysmith
6
- module CLI
7
- module Processors
8
- # Handles the Command Line Interface (CLI) for building of a project skeleton.
9
- class Build
10
- using Refinements::Structs
11
-
12
- # Order is important.
13
- MINIMUM = [
14
- Builders::Core,
15
- Builders::Bundler,
16
- Builders::Pragma,
17
- Builders::Rubocop::Formatter
18
- ].freeze
19
-
20
- # Order is important.
21
- MAXIMUM = [
22
- Builders::Core,
23
- Builders::Documentation,
24
- Builders::Git::Setup,
25
- Builders::Bundler,
26
- Builders::Rake,
27
- Builders::Console,
28
- Builders::Setup,
29
- Builders::Guard,
30
- Builders::Reek,
31
- Builders::RSpec::Context,
32
- Builders::RSpec::Helper,
33
- Builders::Pragma,
34
- Builders::Rubocop::Setup,
35
- Builders::Rubocop::Formatter,
36
- Builders::Git::Commit
37
- ].freeze
38
-
39
- def self.with_minimum = new(builders: MINIMUM)
40
-
41
- def initialize configuration: Configuration::Loader.call, builders: MAXIMUM
42
- @configuration = configuration
43
- @builders = builders
44
- end
45
-
46
- def call(options) = configuration.merge(**options).then { |config| process config }
47
-
48
- private
49
-
50
- attr_reader :configuration, :builders
51
-
52
- def process(config) = builders.each { |builder| builder.call config }
53
- end
54
- end
55
- end
56
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Rubysmith
4
- module CLI
5
- module Processors
6
- # Handles the Command Line Interface (CLI) configuration processing.
7
- class Config
8
- def initialize configuration: CLI::Configuration::Loader::CLIENT, kernel: Kernel
9
- @configuration = configuration
10
- @kernel = kernel
11
- end
12
-
13
- def call action
14
- case action
15
- when :edit then edit
16
- when :view then view
17
- else fail StandardError, "Invalid configuration action: #{action}."
18
- end
19
- end
20
-
21
- private
22
-
23
- attr_reader :configuration, :kernel
24
-
25
- def edit = kernel.system("$EDITOR #{configuration.current}")
26
-
27
- def view = kernel.system("cat #{configuration.current}")
28
- end
29
- end
30
- end
31
- end