rubysmith 0.9.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/bin/rubysmith +0 -1
  5. data/lib/rubysmith.rb +3 -2
  6. data/lib/rubysmith/builder.rb +13 -26
  7. data/lib/rubysmith/builders/bundler.rb +6 -8
  8. data/lib/rubysmith/builders/console.rb +6 -8
  9. data/lib/rubysmith/builders/core.rb +7 -8
  10. data/lib/rubysmith/builders/documentation.rb +16 -21
  11. data/lib/rubysmith/builders/git/commit.rb +7 -11
  12. data/lib/rubysmith/builders/git/setup.rb +6 -8
  13. data/lib/rubysmith/builders/guard.rb +9 -9
  14. data/lib/rubysmith/builders/pragma.rb +8 -13
  15. data/lib/rubysmith/builders/rake.rb +5 -7
  16. data/lib/rubysmith/builders/reek.rb +6 -8
  17. data/lib/rubysmith/builders/rspec/context.rb +10 -11
  18. data/lib/rubysmith/builders/rspec/helper.rb +6 -8
  19. data/lib/rubysmith/builders/rubocop/formatter.rb +5 -7
  20. data/lib/rubysmith/builders/rubocop/setup.rb +7 -9
  21. data/lib/rubysmith/builders/ruby_critic.rb +6 -8
  22. data/lib/rubysmith/builders/setup.rb +8 -8
  23. data/lib/rubysmith/cli/configuration/content.rb +69 -0
  24. data/lib/rubysmith/cli/{defaults.yml → configuration/defaults.yml} +0 -0
  25. data/lib/rubysmith/cli/configuration/loader.rb +35 -0
  26. data/lib/rubysmith/cli/parsers.rb +11 -0
  27. data/lib/rubysmith/cli/parsers/assembler.rb +10 -15
  28. data/lib/rubysmith/cli/parsers/build.rb +4 -6
  29. data/lib/rubysmith/cli/parsers/core.rb +5 -9
  30. data/lib/rubysmith/cli/processors/build.rb +9 -8
  31. data/lib/rubysmith/cli/processors/config.rb +3 -7
  32. data/lib/rubysmith/cli/shell.rb +7 -14
  33. data/lib/rubysmith/identity.rb +1 -1
  34. data/lib/rubysmith/pathway.rb +3 -9
  35. data/lib/rubysmith/renderers/erb.rb +7 -9
  36. data/lib/rubysmith/renderers/namespace.rb +1 -3
  37. data/lib/rubysmith/templates/%project_name%/.rubocop.yml.erb +1 -1
  38. data/lib/rubysmith/templates/%project_name%/CHANGES.adoc.erb +1 -1
  39. data/lib/rubysmith/templates/%project_name%/CHANGES.md.erb +1 -1
  40. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.adoc.erb +2 -2
  41. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.md.erb +1 -1
  42. data/lib/rubysmith/templates/%project_name%/Gemfile.erb +14 -14
  43. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.adoc.erb +1 -1
  44. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.md.erb +1 -1
  45. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.adoc.erb +1 -1
  46. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.md.erb +1 -1
  47. data/lib/rubysmith/templates/%project_name%/README.adoc.erb +5 -5
  48. data/lib/rubysmith/templates/%project_name%/README.md.erb +5 -5
  49. data/lib/rubysmith/templates/%project_name%/Rakefile.erb +15 -15
  50. data/lib/rubysmith/templates/%project_name%/bin/console.erb +1 -1
  51. data/lib/rubysmith/templates/%project_name%/lib/%project_name%.rb.erb +1 -1
  52. data/lib/rubysmith/templates/%project_name%/spec/spec_helper.rb.erb +6 -4
  53. data/lib/rubysmith/templates/%project_name%/spec/support/shared_contexts/temp_dir.rb.erb +3 -3
  54. metadata +7 -6
  55. metadata.gz.sig +0 -0
  56. data/lib/rubysmith/cli/configuration.rb +0 -30
  57. data/lib/rubysmith/realm.rb +0 -74
@@ -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,69 @@
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_audit,
25
+ :build_bundler_leak,
26
+ :build_console,
27
+ :build_documentation,
28
+ :build_git,
29
+ :build_git_lint,
30
+ :build_guard,
31
+ :build_pry,
32
+ :build_reek,
33
+ :build_refinements,
34
+ :build_rspec,
35
+ :build_rubocop,
36
+ :build_ruby_critic,
37
+ :build_setup,
38
+ :build_simple_cov,
39
+ :builders_pragmater_comments,
40
+ :builders_pragmater_includes,
41
+ :version,
42
+ :help,
43
+ keyword_init: true
44
+ ) do
45
+ using Refinements::Strings
46
+
47
+ def initialize *arguments
48
+ super
49
+
50
+ self[:template_root] ||= Pathname(__dir__).join("../../templates").expand_path
51
+ self[:build_root] ||= Pathname.pwd
52
+ freeze
53
+ end
54
+
55
+ def with(attributes) = self.class.new(to_h.merge(attributes))
56
+
57
+ def project_label = project_name.titleize
58
+
59
+ def project_class = project_name.camelcase
60
+
61
+ def project_root = build_root.join(project_name)
62
+
63
+ def to_pathway
64
+ Pathway[start_root: template_root, start_path: template_path, end_root: build_root]
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -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
@@ -6,13 +6,11 @@ module Rubysmith
6
6
  # Handles parsing of Command Line Interface (CLI) build options.
7
7
  # :reek:TooManyMethods
8
8
  class Build
9
- def self.call client:, options:
10
- new(client: client, options: options).call
11
- end
9
+ def self.call(options: {}, client: CLIENT) = new(options: options, client: client).call
12
10
 
13
- def initialize client: CLIENT, options: {}
14
- @client = client
11
+ def initialize options: {}, client: CLIENT
15
12
  @options = options
13
+ @client = client
16
14
  end
17
15
 
18
16
  def call arguments = []
@@ -23,7 +21,7 @@ module Rubysmith
23
21
 
24
22
  private
25
23
 
26
- attr_reader :client, :options
24
+ attr_reader :options, :client
27
25
 
28
26
  def add_minimum
29
27
  client.on "--min", "Use minimum/no options." do |value|