rubysmith 0.10.0 → 0.14.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 +111 -41
  4. data/lib/rubysmith/builder.rb +11 -16
  5. data/lib/rubysmith/builders/bundler.rb +3 -3
  6. data/lib/rubysmith/builders/{ruby_critic.rb → circle_ci.rb} +6 -5
  7. data/lib/rubysmith/builders/console.rb +1 -1
  8. data/lib/rubysmith/builders/core.rb +6 -2
  9. data/lib/rubysmith/builders/documentation/change.rb +32 -0
  10. data/lib/rubysmith/builders/documentation/conduct.rb +32 -0
  11. data/lib/rubysmith/builders/documentation/contribution.rb +32 -0
  12. data/lib/rubysmith/builders/documentation/license.rb +36 -0
  13. data/lib/rubysmith/builders/documentation/readme.rb +44 -0
  14. data/lib/rubysmith/builders/git/commit.rb +1 -1
  15. data/lib/rubysmith/builders/git/setup.rb +1 -1
  16. data/lib/rubysmith/builders/git_hub.rb +34 -0
  17. data/lib/rubysmith/builders/guard.rb +1 -1
  18. data/lib/rubysmith/builders/pragma.rb +1 -1
  19. data/lib/rubysmith/builders/rake.rb +3 -1
  20. data/lib/rubysmith/builders/reek.rb +1 -1
  21. data/lib/rubysmith/builders/rspec/context.rb +1 -1
  22. data/lib/rubysmith/builders/rspec/helper.rb +1 -1
  23. data/lib/rubysmith/builders/rubocop/formatter.rb +1 -1
  24. data/lib/rubysmith/builders/rubocop/setup.rb +1 -1
  25. data/lib/rubysmith/builders/setup.rb +1 -1
  26. data/lib/rubysmith/cli/actions/build.rb +48 -0
  27. data/lib/rubysmith/cli/actions/config.rb +33 -0
  28. data/lib/rubysmith/cli/configuration/content.rb +47 -19
  29. data/lib/rubysmith/cli/configuration/defaults.yml +16 -9
  30. data/lib/rubysmith/cli/configuration/enhancers/current_time.rb +26 -0
  31. data/lib/rubysmith/cli/configuration/enhancers/git_hub_user.rb +33 -0
  32. data/lib/rubysmith/cli/configuration/enhancers/version.rb +26 -0
  33. data/lib/rubysmith/cli/configuration/loader.rb +15 -4
  34. data/lib/rubysmith/cli/parsers/assembler.rb +7 -9
  35. data/lib/rubysmith/cli/parsers/build.rb +174 -49
  36. data/lib/rubysmith/cli/parsers/core.rb +14 -9
  37. data/lib/rubysmith/cli/shell.rb +16 -28
  38. data/lib/rubysmith/container.rb +37 -0
  39. data/lib/rubysmith/identity.rb +2 -2
  40. data/lib/rubysmith/renderers/erb.rb +1 -1
  41. data/lib/rubysmith/renderers/namespace.rb +2 -2
  42. data/lib/rubysmith/templates/%project_name%/.circleci/config.yml.erb +31 -0
  43. data/lib/rubysmith/templates/%project_name%/.github/ISSUE_TEMPLATE.md.erb +14 -0
  44. data/lib/rubysmith/templates/%project_name%/.github/PULL_REQUEST_TEMPLATE.md.erb +11 -0
  45. data/lib/rubysmith/templates/%project_name%/Gemfile.erb +51 -52
  46. data/lib/rubysmith/templates/%project_name%/README.adoc.erb +4 -0
  47. data/lib/rubysmith/templates/%project_name%/README.md.erb +3 -0
  48. data/lib/rubysmith/templates/%project_name%/Rakefile.erb +1 -13
  49. data/lib/rubysmith/templates/%project_name%/bin/console.erb +1 -1
  50. data/lib/rubysmith/templates/%project_name%/lib/%project_path%.rb.erb +12 -0
  51. data/lib/rubysmith/templates/%project_name%/spec/spec_helper.rb.erb +1 -1
  52. data/lib/rubysmith.rb +13 -31
  53. data.tar.gz.sig +0 -0
  54. metadata +92 -11
  55. metadata.gz.sig +0 -0
  56. data/lib/rubysmith/builders/documentation.rb +0 -57
  57. data/lib/rubysmith/cli/processors/build.rb +0 -59
  58. data/lib/rubysmith/cli/processors/config.rb +0 -31
  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
@@ -4,7 +4,7 @@ module Rubysmith
4
4
  module Builders
5
5
  # Builds project skeleton Rake support.
6
6
  class Rake
7
- def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
7
+ def self.call(...) = new(...).call
8
8
 
9
9
  def initialize configuration, builder: Builder
10
10
  @configuration = configuration
@@ -12,6 +12,8 @@ module Rubysmith
12
12
  end
13
13
 
14
14
  def call
15
+ return unless configuration.build_rake
16
+
15
17
  builder.call(configuration.with(template_path: "%project_name%/Rakefile.erb"))
16
18
  .render
17
19
  .replace(/\[\s+/, "[")
@@ -4,7 +4,7 @@ module Rubysmith
4
4
  module Builders
5
5
  # Builds project skeleton Reek code quality support.
6
6
  class Reek
7
- def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
7
+ def self.call(...) = new(...).call
8
8
 
9
9
  def initialize configuration, builder: Builder
10
10
  @configuration = configuration
@@ -5,7 +5,7 @@ module Rubysmith
5
5
  module RSpec
6
6
  # Builds RSpec shared context for temporary directories.
7
7
  class Context
8
- def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
8
+ def self.call(...) = new(...).call
9
9
 
10
10
  def initialize configuration, builder: Builder
11
11
  @configuration = configuration
@@ -5,7 +5,7 @@ module Rubysmith
5
5
  module RSpec
6
6
  # Builds RSpec spec helper for project skeleton.
7
7
  class Helper
8
- def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
8
+ def self.call(...) = new(...).call
9
9
 
10
10
  def initialize configuration, builder: Builder
11
11
  @configuration = configuration
@@ -10,7 +10,7 @@ module Rubysmith
10
10
  class Formatter
11
11
  using Refinements::IOs
12
12
 
13
- def self.call(configuration) = new(configuration).call
13
+ def self.call(...) = new(...).call
14
14
 
15
15
  def initialize configuration, client: RuboCop::CLI.new
16
16
  @configuration = configuration
@@ -5,7 +5,7 @@ module Rubysmith
5
5
  module Rubocop
6
6
  # Builds project skeleton for Rubocop code quality support.
7
7
  class Setup
8
- def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
8
+ def self.call(...) = new(...).call
9
9
 
10
10
  def initialize configuration, builder: Builder
11
11
  @configuration = configuration
@@ -4,7 +4,7 @@ module Rubysmith
4
4
  module Builders
5
5
  # Builds project skeleton setup script.
6
6
  class Setup
7
- def self.call(configuration, builder: Builder) = new(configuration, builder: builder).call
7
+ def self.call(...) = new(...).call
8
8
 
9
9
  def initialize configuration, builder: Builder
10
10
  @configuration = configuration
@@ -0,0 +1,48 @@
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::Readme,
12
+ Builders::Documentation::Change,
13
+ Builders::Documentation::Conduct,
14
+ Builders::Documentation::Contribution,
15
+ Builders::Documentation::License,
16
+ Builders::Git::Setup,
17
+ Builders::Bundler,
18
+ Builders::Rake,
19
+ Builders::Console,
20
+ Builders::CircleCI,
21
+ Builders::Setup,
22
+ Builders::GitHub,
23
+ Builders::Guard,
24
+ Builders::Reek,
25
+ Builders::RSpec::Context,
26
+ Builders::RSpec::Helper,
27
+ Builders::Pragma,
28
+ Builders::Rubocop::Setup,
29
+ Builders::Rubocop::Formatter,
30
+ Builders::Git::Commit
31
+ ].freeze
32
+
33
+ def initialize builders: BUILDERS, container: Container
34
+ @builders = builders
35
+ @container = container
36
+ end
37
+
38
+ def call = builders.each { |builder| builder.call configuration }
39
+
40
+ private
41
+
42
+ attr_reader :builders, :container
43
+
44
+ def configuration = container[__method__]
45
+ end
46
+ end
47
+ end
48
+ 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,38 +8,48 @@ 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
- :build_bundler_audit,
25
19
  :build_bundler_leak,
20
+ :build_changes,
21
+ :build_circle_ci,
22
+ :build_conduct,
26
23
  :build_console,
27
- :build_documentation,
24
+ :build_contributions,
25
+ :build_debug,
28
26
  :build_git,
27
+ :build_git_hub,
29
28
  :build_git_lint,
30
29
  :build_guard,
31
- :build_pry,
30
+ :build_license,
31
+ :build_maximum,
32
+ :build_minimum,
33
+ :build_rake,
34
+ :build_readme,
32
35
  :build_reek,
33
36
  :build_refinements,
34
37
  :build_rspec,
35
38
  :build_rubocop,
36
- :build_ruby_critic,
37
39
  :build_setup,
38
40
  :build_simple_cov,
41
+ :build_zeitwerk,
39
42
  :builders_pragmater_comments,
40
43
  :builders_pragmater_includes,
44
+ :documentation_format,
45
+ :documentation_license,
46
+ :git_hub_user,
47
+ :now,
48
+ :project_name,
49
+ :target_root,
50
+ :template_path,
51
+ :template_root,
41
52
  :version,
42
- :help,
43
53
  keyword_init: true
44
54
  ) do
45
55
  using Refinements::Strings
@@ -48,20 +58,38 @@ module Rubysmith
48
58
  super
49
59
 
50
60
  self[:template_root] ||= Pathname(__dir__).join("../../templates").expand_path
51
- self[:build_root] ||= Pathname.pwd
52
- freeze
61
+ self[:target_root] ||= Pathname.pwd
53
62
  end
54
63
 
55
64
  def with(attributes) = self.class.new(to_h.merge(attributes))
56
65
 
66
+ def maximize = update_build_options(true)
67
+
68
+ def minimize = update_build_options(false)
69
+
57
70
  def project_label = project_name.titleize
58
71
 
59
72
  def project_class = project_name.camelcase
60
73
 
61
- def project_root = build_root.join(project_name)
74
+ def project_root = target_root.join(project_name)
75
+
76
+ def project_path = project_name.snakecase
77
+
78
+ def ascii_doc? = documentation_format == "adoc"
79
+
80
+ def markdown? = documentation_format == "md"
62
81
 
63
82
  def to_pathway
64
- Pathway[start_root: template_root, start_path: template_path, end_root: build_root]
83
+ Pathway[start_root: template_root, start_path: template_path, end_root: target_root]
84
+ end
85
+
86
+ private
87
+
88
+ def update_build_options value
89
+ to_h.except(:build_minimum)
90
+ .select { |key, _value| key.start_with? "build_" }
91
+ .each { |key, _value| self[key] = value }
92
+ .then { self }
65
93
  end
66
94
  end
67
95
  end
@@ -1,30 +1,32 @@
1
- :project:
2
- :name:
3
1
  :author:
4
2
  :name:
5
3
  :email:
6
4
  :url:
7
- :documentation:
8
- :format: "md"
9
- :license: "mit"
10
5
  :build:
11
6
  :amazing_print: true
12
- :bundler_audit: true
13
7
  :bundler_leak: true
8
+ :changes: true
9
+ :circle_ci: false
10
+ :conduct: true
14
11
  :console: true
15
- :documentation: true
12
+ :contributions: true
13
+ :debug: true
16
14
  :git: true
15
+ :git_hub: false
17
16
  :git_lint: true
18
17
  :guard: true
18
+ :license: true
19
+ :maximum: false
19
20
  :minimum: false
20
- :pry: true
21
+ :rake: true
22
+ :readme: true
21
23
  :reek: true
22
24
  :refinements: true
23
25
  :rspec: true
24
26
  :rubocop: true
25
- :ruby_critic: true
26
27
  :setup: true
27
28
  :simple_cov: true
29
+ :zeitwerk: true
28
30
  :builders:
29
31
  :pragmater:
30
32
  :comments:
@@ -37,3 +39,8 @@
37
39
  - "**/*Gemfile"
38
40
  - "**/*Guardfile"
39
41
  - "**/*Rakefile"
42
+ :documentation:
43
+ :format: "md"
44
+ :license: "mit"
45
+ :git_hub:
46
+ :user:
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/structs"
4
+
5
+ module Rubysmith
6
+ module CLI
7
+ module Configuration
8
+ module Enhancers
9
+ # Adds current time to content.
10
+ class CurrentTime
11
+ using Refinements::Structs
12
+
13
+ def initialize now = Time.now
14
+ @now = now
15
+ end
16
+
17
+ def call(content) = content.merge(now: now)
18
+
19
+ private
20
+
21
+ attr_reader :now
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "git_plus"
4
+ require "refinements/strings"
5
+ require "refinements/structs"
6
+
7
+ module Rubysmith
8
+ module CLI
9
+ module Configuration
10
+ module Enhancers
11
+ # Dynamically adds GitHub user if user is defined.
12
+ class GitHubUser
13
+ using Refinements::Strings
14
+ using Refinements::Structs
15
+
16
+ def initialize repository: GitPlus::Repository.new
17
+ @repository = repository
18
+ end
19
+
20
+ def call content
21
+ String(content.git_hub_user).blank? ? content.merge(git_hub_user: user) : content
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :repository
27
+
28
+ def user = repository.config_get("github.user")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/structs"
4
+
5
+ module Rubysmith
6
+ module CLI
7
+ module Configuration
8
+ module Enhancers
9
+ # Adds this gem's version to content.
10
+ class Version
11
+ using Refinements::Structs
12
+
13
+ def initialize version = Identity::VERSION_LABEL
14
+ @version = version
15
+ end
16
+
17
+ def call(content) = content.merge(version: version)
18
+
19
+ private
20
+
21
+ attr_reader :version
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -17,18 +17,29 @@ 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
+ ENHANCERS = [
21
+ Enhancers::GitHubUser.new,
22
+ Enhancers::CurrentTime.new,
23
+ Enhancers::Version.new
24
+ ].freeze
21
25
 
22
- def initialize content: Content.new, client: CLIENT
26
+ def self.call(...) = new(...).call
27
+
28
+ def self.with_defaults = new(client: DEFAULTS, enhancers: [])
29
+
30
+ def initialize content: Content.new, client: CLIENT, enhancers: ENHANCERS
23
31
  @content = content
24
32
  @client = client
33
+ @enhancers = enhancers
25
34
  end
26
35
 
27
- def call = content.merge(**client.to_h.flatten_keys)
36
+ def call = enhancers.reduce(preload_content) { |preload, enhancer| enhancer.call preload }
28
37
 
29
38
  private
30
39
 
31
- attr_reader :content, :client
40
+ attr_reader :content, :client, :enhancers
41
+
42
+ def preload_content = content.merge(**client.to_h.flatten_keys)
32
43
  end
33
44
  end
34
45
  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