rubysmith 0.8.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/README.adoc +2 -5
  5. data/bin/rubysmith +0 -4
  6. data/lib/rubysmith.rb +3 -2
  7. data/lib/rubysmith/builder.rb +12 -27
  8. data/lib/rubysmith/builders/bundler.rb +11 -9
  9. data/lib/rubysmith/builders/console.rb +6 -8
  10. data/lib/rubysmith/builders/core.rb +7 -8
  11. data/lib/rubysmith/builders/documentation.rb +16 -21
  12. data/lib/rubysmith/builders/git/commit.rb +7 -11
  13. data/lib/rubysmith/builders/git/setup.rb +6 -8
  14. data/lib/rubysmith/builders/guard.rb +9 -9
  15. data/lib/rubysmith/builders/pragma.rb +9 -14
  16. data/lib/rubysmith/builders/rake.rb +5 -7
  17. data/lib/rubysmith/builders/reek.rb +6 -8
  18. data/lib/rubysmith/builders/rspec/context.rb +10 -11
  19. data/lib/rubysmith/builders/rspec/helper.rb +6 -8
  20. data/lib/rubysmith/builders/rubocop/formatter.rb +5 -7
  21. data/lib/rubysmith/builders/rubocop/setup.rb +7 -9
  22. data/lib/rubysmith/builders/ruby_critic.rb +6 -8
  23. data/lib/rubysmith/builders/setup.rb +8 -8
  24. data/lib/rubysmith/cli/configuration/content.rb +68 -0
  25. data/lib/rubysmith/cli/{defaults.yml → configuration/defaults.yml} +0 -1
  26. data/lib/rubysmith/cli/configuration/loader.rb +35 -0
  27. data/lib/rubysmith/cli/parsers.rb +11 -0
  28. data/lib/rubysmith/cli/parsers/assembler.rb +10 -15
  29. data/lib/rubysmith/cli/parsers/build.rb +4 -12
  30. data/lib/rubysmith/cli/parsers/core.rb +5 -9
  31. data/lib/rubysmith/cli/processors/build.rb +10 -11
  32. data/lib/rubysmith/cli/processors/config.rb +3 -7
  33. data/lib/rubysmith/cli/shell.rb +9 -17
  34. data/lib/rubysmith/identity.rb +1 -1
  35. data/lib/rubysmith/pathway.rb +3 -9
  36. data/lib/rubysmith/renderers/erb.rb +7 -9
  37. data/lib/rubysmith/renderers/namespace.rb +1 -3
  38. data/lib/rubysmith/templates/%project_name%/.rubocop.yml.erb +5 -5
  39. data/lib/rubysmith/templates/%project_name%/CHANGES.adoc.erb +1 -1
  40. data/lib/rubysmith/templates/%project_name%/CHANGES.md.erb +1 -1
  41. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.adoc.erb +2 -2
  42. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.md.erb +1 -1
  43. data/lib/rubysmith/templates/%project_name%/Gemfile.erb +16 -17
  44. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.adoc.erb +1 -1
  45. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.md.erb +1 -1
  46. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.adoc.erb +1 -1
  47. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.md.erb +1 -1
  48. data/lib/rubysmith/templates/%project_name%/README.adoc.erb +5 -5
  49. data/lib/rubysmith/templates/%project_name%/README.md.erb +5 -5
  50. data/lib/rubysmith/templates/%project_name%/Rakefile.erb +13 -19
  51. data/lib/rubysmith/templates/%project_name%/bin/console.erb +1 -1
  52. data/lib/rubysmith/templates/%project_name%/lib/%project_name%.rb.erb +1 -1
  53. data/lib/rubysmith/templates/%project_name%/spec/spec_helper.rb.erb +8 -3
  54. data/lib/rubysmith/templates/%project_name%/spec/support/shared_contexts/temp_dir.rb.erb +4 -4
  55. metadata +19 -18
  56. metadata.gz.sig +0 -0
  57. data/lib/rubysmith/cli/configuration.rb +0 -30
  58. data/lib/rubysmith/realm.rb +0 -74
@@ -6,30 +6,25 @@ module Rubysmith
6
6
  module Builders
7
7
  # Builds project skeleton pragmas so all Ruby strings are frozen by default.
8
8
  class Pragma
9
- def self.call realm
10
- new(realm).call
11
- end
9
+ def self.call(configuration) = new(configuration).call
12
10
 
13
- def initialize realm, runner: Pragmater::Runner
14
- @realm = realm
15
- @runner = runner
11
+ def initialize configuration, client: Pragmater::Runner
12
+ @configuration = configuration
13
+ @client = client
16
14
  end
17
15
 
18
- def call
19
- runner.for(**attributes).call
20
- nil
21
- end
16
+ def call = client.for(**attributes).call && nil
22
17
 
23
18
  private
24
19
 
25
- attr_reader :realm, :runner
20
+ attr_reader :configuration, :client
26
21
 
27
22
  def attributes
28
23
  {
29
24
  action: :insert,
30
- root_dir: realm.project_root,
31
- comments: realm.builders_pragmater_comments,
32
- includes: realm.builders_pragmater_includes
25
+ root_dir: configuration.project_root,
26
+ comments: configuration.builders_pragmater_comments,
27
+ includes: configuration.builders_pragmater_includes
33
28
  }
34
29
  end
35
30
  end
@@ -4,17 +4,15 @@ module Rubysmith
4
4
  module Builders
5
5
  # Builds project skeleton Rake support.
6
6
  class Rake
7
- def self.call realm, builder: Builder
8
- new(realm, builder: builder).call
9
- end
7
+ def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
10
8
 
11
- def initialize realm, builder: Builder
12
- @realm = realm
9
+ def initialize configuration, builder: Builder
10
+ @configuration = configuration
13
11
  @builder = builder
14
12
  end
15
13
 
16
14
  def call
17
- builder.call(realm.with(template_path: "%project_name%/Rakefile.erb"))
15
+ builder.call(configuration.with(template_path: "%project_name%/Rakefile.erb"))
18
16
  .render
19
17
  .replace(/\[\s+/, "[")
20
18
  .replace(/\s+\]/, "]")
@@ -26,7 +24,7 @@ module Rubysmith
26
24
 
27
25
  private
28
26
 
29
- attr_reader :realm, :builder
27
+ attr_reader :configuration, :builder
30
28
  end
31
29
  end
32
30
  end
@@ -4,24 +4,22 @@ module Rubysmith
4
4
  module Builders
5
5
  # Builds project skeleton Reek code quality support.
6
6
  class Reek
7
- def self.call realm, builder: Builder
8
- new(realm, builder: builder).call
9
- end
7
+ def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
10
8
 
11
- def initialize realm, builder: Builder
12
- @realm = realm
9
+ def initialize configuration, builder: Builder
10
+ @configuration = configuration
13
11
  @builder = builder
14
12
  end
15
13
 
16
14
  def call
17
- return unless realm.build_reek
15
+ return unless configuration.build_reek
18
16
 
19
- builder.call(realm.with(template_path: "%project_name%/.reek.yml.erb")).render
17
+ builder.call(configuration.with(template_path: "%project_name%/.reek.yml.erb")).render
20
18
  end
21
19
 
22
20
  private
23
21
 
24
- attr_reader :realm, :builder
22
+ attr_reader :configuration, :builder
25
23
  end
26
24
  end
27
25
  end
@@ -5,27 +5,26 @@ module Rubysmith
5
5
  module RSpec
6
6
  # Builds RSpec shared context for temporary directories.
7
7
  class Context
8
- def self.call realm, builder: Builder
9
- new(realm, builder: builder).call
10
- end
8
+ def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
11
9
 
12
- def initialize realm, builder: Builder
13
- @realm = realm
10
+ def initialize configuration, builder: Builder
11
+ @configuration = configuration
14
12
  @builder = builder
15
13
  end
16
14
 
17
15
  def call
18
- return unless realm.build_rspec
16
+ return unless configuration.build_rspec
19
17
 
20
- realm.with(template_path: "%project_name%/spec/support/shared_contexts/temp_dir.rb.erb")
21
- .then { |new_realm| builder.call new_realm }
22
- .render
23
- .replace(/\n\s+\n\s+/, "\n ")
18
+ template = "%project_name%/spec/support/shared_contexts/temp_dir.rb.erb"
19
+ configuration.with(template_path: template)
20
+ .then { |updated_configuration| builder.call updated_configuration }
21
+ .render
22
+ .replace(/\n\s+\n\s+/, "\n ")
24
23
  end
25
24
 
26
25
  private
27
26
 
28
- attr_reader :realm, :builder
27
+ attr_reader :configuration, :builder
29
28
  end
30
29
  end
31
30
  end
@@ -5,19 +5,17 @@ module Rubysmith
5
5
  module RSpec
6
6
  # Builds RSpec spec helper for project skeleton.
7
7
  class Helper
8
- def self.call realm, builder: Builder
9
- new(realm, builder: builder).call
10
- end
8
+ def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
11
9
 
12
- def initialize realm, builder: Builder
13
- @realm = realm
10
+ def initialize configuration, builder: Builder
11
+ @configuration = configuration
14
12
  @builder = builder
15
13
  end
16
14
 
17
15
  def call
18
- return unless realm.build_rspec
16
+ return unless configuration.build_rspec
19
17
 
20
- builder.call(realm.with(template_path: "%project_name%/spec/spec_helper.rb.erb"))
18
+ builder.call(configuration.with(template_path: "%project_name%/spec/spec_helper.rb.erb"))
21
19
  .render
22
20
  .replace(/\n{3,}/, "\n\n")
23
21
  .replace(/\n\s{2}(?=(require|Simple|using|Pathname|Dir))/, "\n")
@@ -25,7 +23,7 @@ module Rubysmith
25
23
 
26
24
  private
27
25
 
28
- attr_reader :realm, :builder
26
+ attr_reader :configuration, :builder
29
27
  end
30
28
  end
31
29
  end
@@ -10,23 +10,21 @@ module Rubysmith
10
10
  class Formatter
11
11
  using Refinements::IOs
12
12
 
13
- def self.call realm
14
- new(realm).call
15
- end
13
+ def self.call(configuration) = new(configuration).call
16
14
 
17
- def initialize realm, client: RuboCop::CLI.new
18
- @realm = realm
15
+ def initialize configuration, client: RuboCop::CLI.new
16
+ @configuration = configuration
19
17
  @client = client
20
18
  end
21
19
 
22
20
  def call
23
- STDOUT.squelch { client.run ["--auto-correct", realm.project_root.to_s] }
21
+ STDOUT.squelch { client.run ["--auto-correct", configuration.project_root.to_s] }
24
22
  nil
25
23
  end
26
24
 
27
25
  private
28
26
 
29
- attr_reader :realm, :client
27
+ attr_reader :configuration, :client
30
28
  end
31
29
  end
32
30
  end
@@ -5,28 +5,26 @@ module Rubysmith
5
5
  module Rubocop
6
6
  # Builds project skeleton for Rubocop code quality support.
7
7
  class Setup
8
- def self.call realm, builder: Builder
9
- new(realm, builder: builder).call
10
- end
8
+ def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
11
9
 
12
- def initialize realm, builder: Builder
13
- @realm = realm
10
+ def initialize configuration, builder: Builder
11
+ @configuration = configuration
14
12
  @builder = builder
15
13
  end
16
14
 
17
15
  def call
18
- return unless realm.build_rubocop
16
+ return unless configuration.build_rubocop
19
17
 
20
- builder.call(realm.with(template_path: "%project_name%/bin/rubocop.erb"))
18
+ builder.call(configuration.with(template_path: "%project_name%/bin/rubocop.erb"))
21
19
  .render
22
20
  .permit 0o755
23
21
 
24
- builder.call(realm.with(template_path: "%project_name%/.rubocop.yml.erb")).render
22
+ builder.call(configuration.with(template_path: "%project_name%/.rubocop.yml.erb")).render
25
23
  end
26
24
 
27
25
  private
28
26
 
29
- attr_reader :realm, :builder
27
+ attr_reader :configuration, :builder
30
28
  end
31
29
  end
32
30
  end
@@ -4,24 +4,22 @@ module Rubysmith
4
4
  module Builders
5
5
  # Builds project skeleton RubyCritic code quality support.
6
6
  class RubyCritic
7
- def self.call realm, builder: Builder
8
- new(realm, builder: builder).call
9
- end
7
+ def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
10
8
 
11
- def initialize realm, builder: Builder
12
- @realm = realm
9
+ def initialize configuration, builder: Builder
10
+ @configuration = configuration
13
11
  @builder = builder
14
12
  end
15
13
 
16
14
  def call
17
- return unless realm.build_ruby_critic
15
+ return unless configuration.build_ruby_critic
18
16
 
19
- builder.call(realm.with(template_path: "%project_name%/.rubycritic.yml.erb")).render
17
+ builder.call(configuration.with(template_path: "%project_name%/.rubycritic.yml.erb")).render
20
18
  end
21
19
 
22
20
  private
23
21
 
24
- attr_reader :realm, :builder
22
+ attr_reader :configuration, :builder
25
23
  end
26
24
  end
27
25
  end
@@ -4,24 +4,24 @@ module Rubysmith
4
4
  module Builders
5
5
  # Builds project skeleton setup script.
6
6
  class Setup
7
- def self.call realm, builder: Builder
8
- new(realm, builder: builder).call
9
- end
7
+ def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
10
8
 
11
- def initialize realm, builder: Builder
12
- @realm = realm
9
+ def initialize configuration, builder: Builder
10
+ @configuration = configuration
13
11
  @builder = builder
14
12
  end
15
13
 
16
14
  def call
17
- return unless realm.build_setup
15
+ return unless configuration.build_setup
18
16
 
19
- builder.call(realm.with(template_path: "%project_name%/bin/setup.erb")).render.permit 0o755
17
+ builder.call(configuration.with(template_path: "%project_name%/bin/setup.erb"))
18
+ .render
19
+ .permit 0o755
20
20
  end
21
21
 
22
22
  private
23
23
 
24
- attr_reader :realm, :builder
24
+ attr_reader :configuration, :builder
25
25
  end
26
26
  end
27
27
  end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "refinements/strings"
5
+
6
+ module Rubysmith
7
+ module CLI
8
+ module Configuration
9
+ # Defines the common configuration content for use throughout the gem.
10
+ Content = Struct.new(
11
+ :config,
12
+ :template_root,
13
+ :template_path,
14
+ :build_root,
15
+ :project_name,
16
+ :author_name,
17
+ :author_email,
18
+ :author_url,
19
+ :now,
20
+ :documentation_format,
21
+ :documentation_license,
22
+ :build_minimum,
23
+ :build_amazing_print,
24
+ :build_bundler_leak,
25
+ :build_console,
26
+ :build_documentation,
27
+ :build_git,
28
+ :build_git_lint,
29
+ :build_guard,
30
+ :build_pry,
31
+ :build_reek,
32
+ :build_refinements,
33
+ :build_rspec,
34
+ :build_rubocop,
35
+ :build_ruby_critic,
36
+ :build_setup,
37
+ :build_simple_cov,
38
+ :builders_pragmater_comments,
39
+ :builders_pragmater_includes,
40
+ :version,
41
+ :help,
42
+ keyword_init: true
43
+ ) do
44
+ using Refinements::Strings
45
+
46
+ def initialize *arguments
47
+ super
48
+
49
+ self[:template_root] ||= Pathname(__dir__).join("../../templates").expand_path
50
+ self[:build_root] ||= Pathname.pwd
51
+ freeze
52
+ end
53
+
54
+ def with(attributes) = self.class.new(to_h.merge(attributes))
55
+
56
+ def project_label = project_name.titleize
57
+
58
+ def project_class = project_name.camelcase
59
+
60
+ def project_root = build_root.join(project_name)
61
+
62
+ def to_pathway
63
+ Pathway[start_root: template_root, start_path: template_path, end_root: build_root]
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -9,7 +9,6 @@
9
9
  :license: "mit"
10
10
  :build:
11
11
  :amazing_print: true
12
- :bundler_audit: true
13
12
  :bundler_leak: true
14
13
  :console: true
15
14
  :documentation: true
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "refinements/hashes"
5
+ require "refinements/structs"
6
+ require "runcom"
7
+ require "yaml"
8
+
9
+ module Rubysmith
10
+ module CLI
11
+ module Configuration
12
+ # Represents the fully assembled Command Line Interface (CLI) configuration.
13
+ class Loader
14
+ using Refinements::Hashes
15
+ using Refinements::Structs
16
+
17
+ DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze
18
+ CLIENT = Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: DEFAULTS
19
+
20
+ def self.call = new.call
21
+
22
+ def initialize content: Content.new, client: CLIENT
23
+ @content = content
24
+ @client = client
25
+ end
26
+
27
+ def call = content.merge(**client.to_h.flatten_keys)
28
+
29
+ private
30
+
31
+ attr_reader :content, :client
32
+ end
33
+ end
34
+ end
35
+ end
@@ -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,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