rubysmith 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE.adoc +162 -0
  5. data/README.adoc +207 -0
  6. data/bin/rubysmith +11 -0
  7. data/lib/rubysmith.rb +30 -0
  8. data/lib/rubysmith/builder.rb +145 -0
  9. data/lib/rubysmith/builders/bundler.rb +34 -0
  10. data/lib/rubysmith/builders/console.rb +29 -0
  11. data/lib/rubysmith/builders/core.rb +29 -0
  12. data/lib/rubysmith/builders/documentation.rb +60 -0
  13. data/lib/rubysmith/builders/git/commit.rb +45 -0
  14. data/lib/rubysmith/builders/git/setup.rb +29 -0
  15. data/lib/rubysmith/builders/guard.rb +28 -0
  16. data/lib/rubysmith/builders/pragma.rb +37 -0
  17. data/lib/rubysmith/builders/rake.rb +32 -0
  18. data/lib/rubysmith/builders/reek.rb +27 -0
  19. data/lib/rubysmith/builders/rspec/context.rb +31 -0
  20. data/lib/rubysmith/builders/rspec/helper.rb +33 -0
  21. data/lib/rubysmith/builders/rubocop.rb +43 -0
  22. data/lib/rubysmith/builders/setup.rb +27 -0
  23. data/lib/rubysmith/cli/configuration.rb +29 -0
  24. data/lib/rubysmith/cli/defaults.yml +34 -0
  25. data/lib/rubysmith/cli/parsers/assembler.rb +39 -0
  26. data/lib/rubysmith/cli/parsers/build.rb +101 -0
  27. data/lib/rubysmith/cli/parsers/core.rb +59 -0
  28. data/lib/rubysmith/cli/processors/build.rb +44 -0
  29. data/lib/rubysmith/cli/processors/config.rb +35 -0
  30. data/lib/rubysmith/cli/shell.rb +61 -0
  31. data/lib/rubysmith/identity.rb +11 -0
  32. data/lib/rubysmith/pathway.rb +37 -0
  33. data/lib/rubysmith/realm.rb +69 -0
  34. data/lib/rubysmith/renderers/erb.rb +29 -0
  35. data/lib/rubysmith/renderers/namespace.rb +47 -0
  36. data/lib/rubysmith/templates/%project_name%/.reek.yml.erb +3 -0
  37. data/lib/rubysmith/templates/%project_name%/.rubocop.yml.erb +7 -0
  38. data/lib/rubysmith/templates/%project_name%/.ruby-version.erb +1 -0
  39. data/lib/rubysmith/templates/%project_name%/CHANGES.adoc.erb +5 -0
  40. data/lib/rubysmith/templates/%project_name%/CHANGES.md.erb +5 -0
  41. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.adoc.erb +114 -0
  42. data/lib/rubysmith/templates/%project_name%/CODE_OF_CONDUCT.md.erb +115 -0
  43. data/lib/rubysmith/templates/%project_name%/CONTRIBUTING.adoc.erb +22 -0
  44. data/lib/rubysmith/templates/%project_name%/CONTRIBUTING.md.erb +22 -0
  45. data/lib/rubysmith/templates/%project_name%/Gemfile.erb +33 -0
  46. data/lib/rubysmith/templates/%project_name%/Guardfile.erb +5 -0
  47. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.adoc.erb +162 -0
  48. data/lib/rubysmith/templates/%project_name%/LICENSE-apache.md.erb +162 -0
  49. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.adoc.erb +20 -0
  50. data/lib/rubysmith/templates/%project_name%/LICENSE-mit.md.erb +20 -0
  51. data/lib/rubysmith/templates/%project_name%/README.adoc.erb +78 -0
  52. data/lib/rubysmith/templates/%project_name%/README.md.erb +66 -0
  53. data/lib/rubysmith/templates/%project_name%/Rakefile.erb +33 -0
  54. data/lib/rubysmith/templates/%project_name%/bin/console.erb +11 -0
  55. data/lib/rubysmith/templates/%project_name%/bin/guard.erb +6 -0
  56. data/lib/rubysmith/templates/%project_name%/bin/rubocop.erb +7 -0
  57. data/lib/rubysmith/templates/%project_name%/bin/setup.erb +8 -0
  58. data/lib/rubysmith/templates/%project_name%/lib/%project_name%.rb.erb +1 -0
  59. data/lib/rubysmith/templates/%project_name%/lib/%project_name%/identity.rb.erb +8 -0
  60. data/lib/rubysmith/templates/%project_name%/spec/spec_helper.rb.erb +34 -0
  61. data/lib/rubysmith/templates/%project_name%/spec/support/shared_contexts/temp_dir.rb.erb +9 -0
  62. data/lib/rubysmith/text/inserter.rb +31 -0
  63. metadata +367 -0
  64. metadata.gz.sig +0 -0
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ # Builds project skeleton setup script.
6
+ class Setup
7
+ def self.call realm, builder: Builder
8
+ new(realm, builder: builder).call
9
+ end
10
+
11
+ def initialize realm, builder: Builder
12
+ @realm = realm
13
+ @builder = builder
14
+ end
15
+
16
+ def call
17
+ return unless realm.build_setup
18
+
19
+ builder.call(realm.with(template_path: "%project_name%/bin/setup.erb")).render.permit 0o755
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :realm, :builder
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
4
+ require "refinements/hashes"
5
+ require "runcom"
6
+
7
+ module Rubysmith
8
+ module CLI
9
+ # Represents the fully assembled Command Line Interface (CLI) configuration.
10
+ class Configuration
11
+ using Refinements::Hashes
12
+
13
+ DEFAULTS = YAML.load_file(Pathname(__dir__).join("defaults.yml")).freeze
14
+ CLIENT = Runcom::Config.new "#{Identity::NAME}/configuration.yml", defaults: DEFAULTS
15
+
16
+ def initialize client: CLIENT
17
+ @client = client
18
+ end
19
+
20
+ def to_h
21
+ client.to_h.flatten_keys
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :client
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ :project:
2
+ :name:
3
+ :author:
4
+ :name:
5
+ :email:
6
+ :url:
7
+ :documentation:
8
+ :format: "md"
9
+ :license: "mit"
10
+ :build:
11
+ :bundler_audit: true
12
+ :console: true
13
+ :documentation: true
14
+ :git: true
15
+ :git_lint: true
16
+ :guard: true
17
+ :pry: true
18
+ :reek: true
19
+ :rspec: true
20
+ :rubocop: true
21
+ :setup: true
22
+ :simple_cov: true
23
+ :builders:
24
+ :pragmater:
25
+ :comments:
26
+ - "# frozen_string_literal: true"
27
+ :includes:
28
+ - "**/*.rb"
29
+ - "**/*bin/console"
30
+ - "**/*bin/guard"
31
+ - "**/*bin/rubocop"
32
+ - "**/*Gemfile"
33
+ - "**/*Guardfile"
34
+ - "**/*Rakefile"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "runcom"
4
+
5
+ module Rubysmith
6
+ module CLI
7
+ module Parsers
8
+ CLIENT = OptionParser.new nil, 40, " "
9
+ SECTIONS = [Core, Build].freeze # Order is important.
10
+
11
+ # Assembles and parses all Command Line Interface (CLI) options.
12
+ class Assembler
13
+ def initialize client = CLIENT, sections: SECTIONS, configuration: CLI::Configuration.new
14
+ @client = client
15
+ @sections = sections
16
+ @options = configuration.to_h
17
+ end
18
+
19
+ def call arguments = []
20
+ sections.each { |parser| parser.call client: client, options: options }
21
+ client.parse! arguments
22
+ options
23
+ end
24
+
25
+ def to_h
26
+ options
27
+ end
28
+
29
+ def to_s
30
+ client.to_s
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :client, :sections, :options
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module CLI
5
+ module Parsers
6
+ # Handles parsing of Command Line Interface (CLI) build options.
7
+ class Build
8
+ def self.call client:, options:
9
+ new(client: client, options: options).call
10
+ end
11
+
12
+ def initialize client: CLIENT, options: {}
13
+ @client = client
14
+ @options = options
15
+ end
16
+
17
+ def call arguments = []
18
+ client.separator "\nBUILD OPTIONS:\n"
19
+ private_methods.grep(/add_/).each(&method(:__send__))
20
+ arguments.empty? ? arguments : client.parse!(arguments)
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :client, :options
26
+
27
+ def add_bundler_audit
28
+ client.on "--[no-]bundler-audit", "Add Bundler Audit." do |value|
29
+ options[:build_bundler_audit] = value
30
+ end
31
+ end
32
+
33
+ def add_console
34
+ client.on "--[no-]console", "Add console support." do |value|
35
+ options[:build_console] = value
36
+ end
37
+ end
38
+
39
+ def add_documentation
40
+ client.on "--[no-]documentation", "Add Documentation." do |value|
41
+ options[:build_documentation] = value
42
+ end
43
+ end
44
+
45
+ def add_git
46
+ client.on "--[no-]git", "Add Git." do |value|
47
+ options[:build_git] = value
48
+ end
49
+ end
50
+
51
+ def add_git_lint
52
+ client.on "--[no-]git-lint", "Add Git Lint." do |value|
53
+ options[:build_git_lint] = value
54
+ end
55
+ end
56
+
57
+ def add_guard
58
+ client.on "--[no-]guard", "Add Guard." do |value|
59
+ options[:build_guard] = value
60
+ end
61
+ end
62
+
63
+ def add_pry
64
+ client.on "--[no-]pry", "Add Pry." do |value|
65
+ options[:build_pry] = value
66
+ end
67
+ end
68
+
69
+ def add_reek
70
+ client.on "--[no-]reek", "Add Reek." do |value|
71
+ options[:build_reek] = value
72
+ end
73
+ end
74
+
75
+ def add_rspec
76
+ client.on "--[no-]rspec", "Add RSpec." do |value|
77
+ options[:build_rspec] = value
78
+ end
79
+ end
80
+
81
+ def add_rubocop
82
+ client.on "--[no-]rubocop", "Add Rubocop." do |value|
83
+ options[:build_rubocop] = value
84
+ end
85
+ end
86
+
87
+ def add_setup
88
+ client.on "--[no-]setup", "Add setup support." do |value|
89
+ options[:build_setup] = value
90
+ end
91
+ end
92
+
93
+ def add_simple_cov
94
+ client.on "--[no-]simple_cov", "Add SimpleCov." do |value|
95
+ options[:build_simple_cov] = value
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubysmith/identity"
4
+
5
+ module Rubysmith
6
+ module CLI
7
+ module Parsers
8
+ # Handles parsing of Command Line Interface (CLI) core options.
9
+ class Core
10
+ def self.call client:, options:
11
+ new(client: client, options: options).call
12
+ end
13
+
14
+ def initialize client: CLIENT, options: {}
15
+ @client = client
16
+ @options = options
17
+ end
18
+
19
+ def call arguments = []
20
+ client.banner = "#{Identity::LABEL} - #{Identity::SUMMARY}"
21
+ client.separator "\nUSAGE:\n"
22
+ private_methods.grep(/add_/).each(&method(:__send__))
23
+ arguments.empty? ? arguments : client.parse!(arguments)
24
+ end
25
+
26
+ private
27
+
28
+ attr_reader :client, :options
29
+
30
+ def add_config
31
+ client.on "-c",
32
+ "--config ACTION",
33
+ %i[edit view],
34
+ "Manage gem configuration: edit or view." do |action|
35
+ options[:config] = action
36
+ end
37
+ end
38
+
39
+ def add_build
40
+ client.on "-b", "--build NAME [options]", "Build new gem." do |value|
41
+ options[:build] = value
42
+ end
43
+ end
44
+
45
+ def add_version
46
+ client.on "-v", "--version", "Show gem version." do
47
+ options[:version] = Identity::VERSION_LABEL
48
+ end
49
+ end
50
+
51
+ def add_help
52
+ client.on "-h", "--help", "Show this message." do
53
+ options[:help] = true
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module CLI
5
+ module Processors
6
+ # Order is important.
7
+ BUILDERS = [
8
+ Builders::Core,
9
+ Builders::Documentation,
10
+ Builders::Git::Setup,
11
+ Builders::Bundler,
12
+ Builders::Rake,
13
+ Builders::Console,
14
+ Builders::Setup,
15
+ Builders::Guard,
16
+ Builders::Reek,
17
+ Builders::RSpec::Context,
18
+ Builders::RSpec::Helper,
19
+ Builders::Pragma,
20
+ Builders::Rubocop,
21
+ Builders::Git::Commit
22
+ ].freeze
23
+
24
+ # Handles the Command Line Interface (CLI) for building of a project skeleton.
25
+ class Build
26
+ def initialize builders: BUILDERS
27
+ @builders = builders
28
+ end
29
+
30
+ def call options
31
+ Realm[**options].then(&method(:process))
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :builders
37
+
38
+ def process realm
39
+ builders.each { |builder| builder.call realm }
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
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::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
26
+ kernel.system "$EDITOR #{configuration.current}"
27
+ end
28
+
29
+ def view
30
+ kernel.system "cat #{configuration.current}"
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "optparse"
4
+ require "refinements/hashes"
5
+
6
+ module Rubysmith
7
+ module CLI
8
+ # Represents the Command Line Interface (CLI) for this gem.
9
+ class Shell
10
+ using Refinements::Hashes
11
+
12
+ PROCESSORS = {
13
+ config: Processors::Config.new,
14
+ build: Processors::Build.new
15
+ }.freeze
16
+
17
+ def initialize parser: Parsers::Assembler.new, processors: PROCESSORS
18
+ @parser = parser
19
+ @processors = processors
20
+ end
21
+
22
+ def call arguments = []
23
+ parse arguments
24
+
25
+ case options
26
+ in config: action, **remainder then config action
27
+ in build:, **remainder then build options.rekey(build: :project_name).merge now: Time.now
28
+ in version:, **remainder then puts version
29
+ in help:, **remainder then usage
30
+ else usage
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ attr_reader :parser, :processors, :exceptions
37
+
38
+ def parse arguments = []
39
+ parser.call arguments
40
+ rescue StandardError => error
41
+ puts error.message
42
+ end
43
+
44
+ def config action
45
+ processors.fetch(__method__).call action
46
+ end
47
+
48
+ def build settings
49
+ processors.fetch(__method__).call settings
50
+ end
51
+
52
+ def options
53
+ parser.to_h
54
+ end
55
+
56
+ def usage
57
+ puts parser.to_s
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Identity
5
+ NAME = "rubysmith"
6
+ LABEL = "Rubysmith"
7
+ VERSION = "0.1.0"
8
+ VERSION_LABEL = "#{LABEL} #{VERSION}"
9
+ SUMMARY = "A command line interface for smithing Ruby projects."
10
+ end
11
+ end