rubysmith 0.6.1 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) 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 +4 -2
  5. data/bin/rubysmith +0 -4
  6. data/lib/rubysmith.rb +4 -2
  7. data/lib/rubysmith/builder.rb +14 -30
  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 +17 -22
  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 +25 -0
  23. data/lib/rubysmith/builders/setup.rb +8 -8
  24. data/lib/rubysmith/cli/configuration/content.rb +69 -0
  25. data/lib/rubysmith/cli/{defaults.yml → configuration/defaults.yml} +1 -0
  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 +11 -7
  30. data/lib/rubysmith/cli/parsers/core.rb +5 -9
  31. data/lib/rubysmith/cli/processors/build.rb +10 -8
  32. data/lib/rubysmith/cli/processors/config.rb +3 -7
  33. data/lib/rubysmith/cli/shell.rb +12 -18
  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%/.rubycritic.yml.erb +3 -0
  40. data/lib/rubysmith/templates/%project_name%/CHANGES.adoc.erb +1 -1
  41. data/lib/rubysmith/templates/%project_name%/CHANGES.md.erb +1 -1
  42. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.adoc.erb +2 -2
  43. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.md.erb +1 -1
  44. data/lib/rubysmith/templates/%project_name%/Gemfile.erb +21 -16
  45. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.adoc.erb +1 -1
  46. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.md.erb +1 -1
  47. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.adoc.erb +1 -1
  48. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.md.erb +1 -1
  49. data/lib/rubysmith/templates/%project_name%/README.adoc.erb +5 -5
  50. data/lib/rubysmith/templates/%project_name%/README.md.erb +5 -5
  51. data/lib/rubysmith/templates/%project_name%/Rakefile.erb +19 -13
  52. data/lib/rubysmith/templates/%project_name%/bin/console.erb +1 -1
  53. data/lib/rubysmith/templates/%project_name%/bin/guard.erb +0 -1
  54. data/lib/rubysmith/templates/%project_name%/bin/rubocop.erb +0 -1
  55. data/lib/rubysmith/templates/%project_name%/lib/%project_name%.rb.erb +3 -0
  56. data/lib/rubysmith/templates/%project_name%/spec/spec_helper.rb.erb +8 -3
  57. data/lib/rubysmith/templates/%project_name%/spec/support/shared_contexts/temp_dir.rb.erb +4 -4
  58. metadata +28 -25
  59. metadata.gz.sig +0 -0
  60. data/lib/rubysmith/cli/configuration.rb +0 -29
  61. data/lib/rubysmith/realm.rb +0 -73
@@ -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
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ # Builds project skeleton RubyCritic code quality support.
6
+ class RubyCritic
7
+ def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
8
+
9
+ def initialize configuration, builder: Builder
10
+ @configuration = configuration
11
+ @builder = builder
12
+ end
13
+
14
+ def call
15
+ return unless configuration.build_ruby_critic
16
+
17
+ builder.call(configuration.with(template_path: "%project_name%/.rubycritic.yml.erb")).render
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :configuration, :builder
23
+ end
24
+ end
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
@@ -22,6 +22,7 @@
22
22
  :refinements: true
23
23
  :rspec: true
24
24
  :rubocop: true
25
+ :ruby_critic: true
25
26
  :setup: true
26
27
  :simple_cov: true
27
28
  :builders:
@@ -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