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,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler"
4
+ require "bundler/cli"
5
+
6
+ module Rubysmith
7
+ module Builders
8
+ # Builds Bundler Gemfile configuration and installs gem dependencies for project skeleton.
9
+ class Bundler
10
+ def self.call realm, builder: Builder
11
+ new(realm, builder: builder).call
12
+ end
13
+
14
+ def initialize realm, builder: Builder, runner: ::Bundler::CLI
15
+ @realm = realm
16
+ @builder = builder
17
+ @runner = runner
18
+ end
19
+
20
+ def call
21
+ builder.call(realm.with(template_path: "%project_name%/Gemfile.erb"))
22
+ .render
23
+ .replace(/"\n\s{2,}/, "\"\n")
24
+ .replace(/\n\s*gem/, "\n gem")
25
+ Dir.chdir(realm.project_root) { runner.start %w[install --quiet] }
26
+ nil
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :realm, :builder, :runner
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ # Builds project skeleton console for object inspection and exploration.
6
+ class Console
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_console
18
+
19
+ builder.call(realm.with(template_path: "%project_name%/bin/console.erb"))
20
+ .render
21
+ .permit 0o755
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :realm, :builder
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ # Builds project skeleton core structure and minimum file support.
6
+ class Core
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
+ builder.call(realm.with(template_path: "%project_name%/lib/%project_name%/identity.rb.erb"))
18
+ .render
19
+ builder.call(realm.with(template_path: "%project_name%/lib/%project_name%.rb.erb")).render
20
+ builder.call(realm.with(template_path: "%project_name%/.ruby-version.erb")).render
21
+ nil
22
+ end
23
+
24
+ private
25
+
26
+ attr_reader :realm, :builder
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ # Builds project skeleton documentation.
6
+ class Documentation
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_documentation
18
+
19
+ private_methods.grep(/render_/).each(&method(:__send__))
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :realm, :builder
25
+
26
+ def render_changes
27
+ builder.call(realm.with(template_path: "%project_name%/CHANGES.#{kind}.erb"))
28
+ .render
29
+ end
30
+
31
+ def render_conduct
32
+ builder.call(realm.with(template_path: "%project_name%/CODE_OF_CONDUCT.#{kind}.erb"))
33
+ .render
34
+ end
35
+
36
+ def render_contributions
37
+ builder.call(realm.with(template_path: "%project_name%/CONTRIBUTING.#{kind}.erb"))
38
+ .render
39
+ end
40
+
41
+ def render_license
42
+ builder.call(realm.with(template_path: "%project_name%/LICENSE-#{license}.#{kind}.erb"))
43
+ .render
44
+ .rename "LICENSE.#{kind}"
45
+ end
46
+
47
+ def render_readme
48
+ builder.call(realm.with(template_path: "%project_name%/README.#{kind}.erb")).render
49
+ end
50
+
51
+ def kind
52
+ realm.documentation_format || "md"
53
+ end
54
+
55
+ def license
56
+ realm.documentation_license || "mit"
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ module Git
6
+ # Builds project skeleton initial Git commit message.
7
+ class Commit
8
+ def self.call realm, builder: Builder
9
+ new(realm, builder: builder).call
10
+ end
11
+
12
+ def initialize realm, builder: Builder
13
+ @realm = realm
14
+ @builder = builder
15
+ end
16
+
17
+ def call
18
+ return unless realm.build_git
19
+
20
+ builder.call(realm)
21
+ .run("git add .", chdir: project_name)
22
+ .run(
23
+ %(git commit --all --message "Added project skeleton" --message "#{body}"),
24
+ chdir: project_name
25
+ )
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :realm, :builder
31
+
32
+ def body
33
+ <<~CONTENT
34
+ Generated with [#{Identity::LABEL}]("https://www.alchemists.io/projects/rubysmith")
35
+ #{Identity::VERSION}.
36
+ CONTENT
37
+ end
38
+
39
+ def project_name
40
+ realm.project_name
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ module Git
6
+ # Initializes project skeleton as a Git repository.
7
+ class Setup
8
+ def self.call realm, builder: Builder
9
+ new(realm, builder: builder).call
10
+ end
11
+
12
+ def initialize realm, builder: Builder
13
+ @realm = realm
14
+ @builder = builder
15
+ end
16
+
17
+ def call
18
+ return unless realm.build_git
19
+
20
+ builder.call(realm).run("git init", chdir: realm.project_name)
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :realm, :builder
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ # Builds project skeleton Guard support for a red, green, refactor loop.
6
+ class Guard
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_guard
18
+
19
+ builder.call(realm.with(template_path: "%project_name%/bin/guard.erb")).render.permit 0o755
20
+ builder.call(realm.with(template_path: "%project_name%/Guardfile.erb")).render
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :realm, :builder
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pragmater"
4
+
5
+ module Rubysmith
6
+ module Builders
7
+ # Builds project skeleton pragmas so all Ruby strings are frozen by default.
8
+ class Pragma
9
+ def self.call realm
10
+ new(realm).call
11
+ end
12
+
13
+ def initialize realm, runner: Pragmater::Runner
14
+ @realm = realm
15
+ @runner = runner
16
+ end
17
+
18
+ def call
19
+ runner.for(**attributes).call
20
+ nil
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :realm, :runner
26
+
27
+ def attributes
28
+ {
29
+ action: :insert,
30
+ root_dir: realm.project_root,
31
+ comments: realm.builders_pragmater_comments,
32
+ includes: realm.builders_pragmater_includes
33
+ }
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ # Builds project skeleton Rake support.
6
+ class Rake
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
+ builder.call(realm.with(template_path: "%project_name%/Rakefile.erb"))
18
+ .render
19
+ .replace(/\A\n+/, "")
20
+ .replace(/\[\s+/, "[")
21
+ .replace(/\s+\]/, "]")
22
+ .replace(/\n{2,}/, "\n\n")
23
+ .replace(" ", "")
24
+ nil
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :realm, :builder
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ # Builds project skeleton Reek code quality support.
6
+ class Reek
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_reek
18
+
19
+ builder.call(realm.with(template_path: "%project_name%/.reek.yml.erb")).render
20
+ end
21
+
22
+ private
23
+
24
+ attr_reader :realm, :builder
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ module RSpec
6
+ # Builds RSpec shared context for temporary directories.
7
+ class Context
8
+ def self.call realm, builder: Builder
9
+ new(realm, builder: builder).call
10
+ end
11
+
12
+ def initialize realm, builder: Builder
13
+ @realm = realm
14
+ @builder = builder
15
+ end
16
+
17
+ def call
18
+ return unless realm.build_rspec
19
+
20
+ builder.call(
21
+ realm.with(template_path: "%project_name%/spec/support/shared_contexts/temp_dir.rb.erb")
22
+ ).render
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :realm, :builder
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubysmith
4
+ module Builders
5
+ module RSpec
6
+ # Builds RSpec spec helper for project skeleton.
7
+ class Helper
8
+ def self.call realm, builder: Builder
9
+ new(realm, builder: builder).call
10
+ end
11
+
12
+ def initialize realm, builder: Builder
13
+ @realm = realm
14
+ @builder = builder
15
+ end
16
+
17
+ def call
18
+ return unless realm.build_rspec
19
+
20
+ builder.call(realm.with(template_path: "%project_name%/spec/spec_helper.rb.erb"))
21
+ .render
22
+ .replace(/\n{3,}/, "\n\n")
23
+ .replace(" require", "require")
24
+ .replace(" Simple", "Simple")
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :realm, :builder
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubocop"
4
+ require "stringio"
5
+
6
+ module Rubysmith
7
+ module Builders
8
+ # Builds project skeleton Rubocop code quality support.
9
+ class Rubocop
10
+ def self.call realm, builder: Builder
11
+ new(realm, builder: builder).call
12
+ end
13
+
14
+ def initialize realm, builder: Builder, runner: RuboCop::CLI.new
15
+ @realm = realm
16
+ @builder = builder
17
+ @runner = runner
18
+ end
19
+
20
+ def call
21
+ return unless realm.build_rubocop
22
+
23
+ builder.call(realm.with(template_path: "%project_name%/bin/rubocop.erb"))
24
+ .render
25
+ .permit 0o755
26
+
27
+ builder.call(realm.with(template_path: "%project_name%/.rubocop.yml.erb")).render
28
+ auto_correct
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :realm, :builder, :runner
34
+
35
+ def auto_correct
36
+ backup = $stdout
37
+ $stdout = StringIO.new
38
+ runner.run ["--auto-correct", "--format", "quiet", realm.project_root.to_s]
39
+ $stdout = backup
40
+ end
41
+ end
42
+ end
43
+ end