gemsmith 5.6.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +4 -3
  4. data/README.md +90 -54
  5. data/lib/gemsmith.rb +0 -1
  6. data/lib/gemsmith/aids/gem.rb +24 -0
  7. data/lib/gemsmith/aids/git.rb +10 -0
  8. data/lib/gemsmith/aids/spec.rb +41 -0
  9. data/lib/gemsmith/cli.rb +26 -11
  10. data/lib/gemsmith/cli_helpers.rb +20 -69
  11. data/lib/gemsmith/configuration.rb +189 -0
  12. data/lib/gemsmith/identity.rb +2 -2
  13. data/lib/gemsmith/rake/build.rb +17 -19
  14. data/lib/gemsmith/rake/tasks.rb +11 -9
  15. data/lib/gemsmith/skeletons/base_skeleton.rb +6 -9
  16. data/lib/gemsmith/skeletons/bundler_skeleton.rb +1 -1
  17. data/lib/gemsmith/skeletons/cli_skeleton.rb +3 -7
  18. data/lib/gemsmith/skeletons/documentation_skeleton.rb +17 -5
  19. data/lib/gemsmith/skeletons/gem_skeleton.rb +4 -4
  20. data/lib/gemsmith/skeletons/git_skeleton.rb +2 -2
  21. data/lib/gemsmith/skeletons/guard_skeleton.rb +2 -6
  22. data/lib/gemsmith/skeletons/pry_skeleton.rb +11 -0
  23. data/lib/gemsmith/skeletons/rails_skeleton.rb +21 -19
  24. data/lib/gemsmith/skeletons/rake_skeleton.rb +10 -15
  25. data/lib/gemsmith/skeletons/rspec_skeleton.rb +8 -12
  26. data/lib/gemsmith/skeletons/rubocop_skeleton.rb +3 -7
  27. data/lib/gemsmith/skeletons/ruby_skeleton.rb +1 -1
  28. data/lib/gemsmith/skeletons/travis_skeleton.rb +2 -6
  29. data/lib/gemsmith/templates/%gem_name%/%gem_name%.gemspec.tt +23 -29
  30. data/lib/gemsmith/templates/%gem_name%/.gitignore.tt +0 -1
  31. data/lib/gemsmith/templates/%gem_name%/.rubocop.yml.tt +3 -1
  32. data/lib/gemsmith/templates/%gem_name%/.ruby-version.tt +1 -1
  33. data/lib/gemsmith/templates/%gem_name%/.travis.yml.tt +3 -4
  34. data/lib/gemsmith/templates/%gem_name%/CODE_OF_CONDUCT.md.tt +18 -9
  35. data/lib/gemsmith/templates/%gem_name%/Guardfile.tt +1 -1
  36. data/lib/gemsmith/templates/%gem_name%/LICENSE.md.tt +1 -1
  37. data/lib/gemsmith/templates/%gem_name%/README.md.tt +25 -22
  38. data/lib/gemsmith/templates/%gem_name%/Rakefile.tt +1 -1
  39. data/lib/gemsmith/templates/%gem_name%/bin/%gem_name%.tt +5 -5
  40. data/lib/gemsmith/templates/%gem_name%/gemfiles/rails-%rails_version%.x.gemfile.tt +5 -0
  41. data/lib/gemsmith/templates/%gem_name%/lib/%gem_name%.rb.tt +3 -3
  42. data/lib/gemsmith/templates/%gem_name%/lib/%gem_name%/cli.rb.tt +7 -7
  43. data/lib/gemsmith/templates/%gem_name%/lib/%gem_name%/engine.rb.tt +2 -2
  44. data/lib/gemsmith/templates/%gem_name%/lib/%gem_name%/identity.rb.tt +5 -5
  45. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_name%/install/USAGE.tt +2 -2
  46. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_name%/install/install_generator.rb.tt +2 -2
  47. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_name%/upgrade/USAGE.tt +2 -2
  48. data/lib/gemsmith/templates/%gem_name%/lib/generators/%gem_name%/upgrade/upgrade_generator.rb.tt +2 -2
  49. data/lib/gemsmith/templates/%gem_name%/lib/{%gem_name%/tasks → tasks}/rspec.rake.tt +0 -0
  50. data/lib/gemsmith/templates/%gem_name%/lib/{%gem_name%/tasks → tasks}/rubocop.rake.tt +0 -0
  51. data/lib/gemsmith/templates/%gem_name%/spec/lib/%gem_name%/%gem_name%_spec.rb.tt +1 -1
  52. data/lib/gemsmith/templates/%gem_name%/spec/spec_helper.rb.tt +5 -16
  53. data/lib/gemsmith/templates/%gem_name%/spec/support/extensions/pry.rb.tt +6 -0
  54. data/lib/{gemsmith/tasks → tasks}/rspec.rake +0 -0
  55. data/lib/{gemsmith/tasks → tasks}/rubocop.rake +0 -0
  56. metadata +47 -15
  57. metadata.gz.sig +0 -0
  58. data/lib/gemsmith/cli_options.rb +0 -103
  59. data/lib/gemsmith/kit.rb +0 -12
  60. data/lib/gemsmith/templates/%gem_name%/gemfiles/rails-4.1.x.gemfile.tt +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8fae3eed50e6c041a0468c15d995f955f2a12e0
4
- data.tar.gz: d7c8f707c174b7e5f3c80d40a007a56b3d651338
3
+ metadata.gz: 93a8b6f5bd33ee3d2ca49fd60ab5120a5ed16753
4
+ data.tar.gz: 02f7d1a50c6aca870805920c2a85994b7da63030
5
5
  SHA512:
6
- metadata.gz: ec5db0c1fafa1130cb9edaeaacd570bd9f58c352cc0b10fb0a70300f561e8b2f881cede25541b69eb6b5d8325715577383a9dc39dfb9d8377a925927b8174fdc
7
- data.tar.gz: 3d2f2b54e0b818b5a75229dafa41b0f08b5eda1301521d1c72266bed7c2336192d46305edb929f9d919f68e98939188addb8dc93643a075ae55533debf710e67
6
+ metadata.gz: 5c9fccafbe3aef91a6a794261f0f5a6213185784faf2128a5bceb1072af3bf8003c24b9a5a8ffd90457955e2187b8a347e17fbae040a052c286c0767a72837f3
7
+ data.tar.gz: 7830aa4aa2fd4b2d32f7bbb20d57caa607ad658aa142f423ee6a1d7e51bec3e1061ddb682e1a4a42e89785af2a628fea9ba75d3a00b40137948d3a22fe8e2fc1
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
@@ -1,3 +1,4 @@
1
- :�Z"�b>�;@9��]��q�
2
- �)0���|πF@�mz��gMuSUw4�t} ߕaIy�D �L@��-'z4k��r7�@@J� +�9�iΈ�X���gx�t��0 �q�e���Zf� ª�}�
3
- ^�sB��UmY�ށ,Aj9L;�+u�)��~Ry�I��+�B�Tc���"у��$��E���&���eW�DN=���"�z�na8�o����H,�`�k�p6�����.X��oBdo'�i�
1
+
2
+ O�-�W�~~�����_��� ��y�7Z�-�jpa��tJ7_�-��#3���aT�A
3
+ H�-�9a8lQK�X;���w���%��;,W����!}+c 0l��?1^f��7���~.9E"���$�Nf��Mgy^���Y�҉�
4
+ ���Ć��EI�Q˧~�� �*r/�l����AX?-x���0'%���<��+���� e���+%H4
data/README.md CHANGED
@@ -5,11 +5,12 @@
5
5
  [![Code Climate Coverage](https://codeclimate.com/github/bkuhlmann/gemsmith/coverage.svg)](https://codeclimate.com/github/bkuhlmann/gemsmith)
6
6
  [![Gemnasium Status](https://gemnasium.com/bkuhlmann/gemsmith.svg)](https://gemnasium.com/bkuhlmann/gemsmith)
7
7
  [![Travis CI Status](https://secure.travis-ci.org/bkuhlmann/gemsmith.svg)](http://travis-ci.org/bkuhlmann/gemsmith)
8
+ [![Patreon](https://img.shields.io/badge/patreon-donate-brightgreen.svg)](https://www.patreon.com/bkuhlmann)
8
9
 
9
10
  A command line interface for smithing new Ruby gems.
10
11
 
11
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
12
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
12
+ <!-- Tocer[start]: Auto-generated, don't remove. -->
13
+
13
14
  # Table of Contents
14
15
 
15
16
  - [Features](#features)
@@ -31,32 +32,33 @@ A command line interface for smithing new Ruby gems.
31
32
  - [History](#history)
32
33
  - [Credits](#credits)
33
34
 
34
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
35
+ <!-- Tocer[finish]: Auto-generated, don't remove. -->
35
36
 
36
37
  # Features
37
38
 
38
- - Builds a gem skeleton with Bundler functionality in mind.
39
+ - Builds a gem skeleton with enhanced Bundler functionality.
39
40
  - Supports common settings to be applied when creating new gems.
40
- - Supports [Thor](https://github.com/wycats/thor) command line functionality.
41
+ - Supports [Thor](https://github.com/wycats/thor) command line interface (CLI) functionality.
41
42
  - Supports [Ruby on Rails](http://rubyonrails.org).
42
- - Supports [RSpec](http://rspec.info).
43
- - Supports [Rubocop](https://github.com/bbatsov/rubocop).
44
43
  - Supports [Pry](http://pryrepl.org).
45
44
  - Supports [Guard](https://github.com/guard/guard).
45
+ - Supports [RSpec](http://rspec.info).
46
+ - Supports [Rubocop](https://github.com/bbatsov/rubocop).
46
47
  - Supports [Code Climate](https://codeclimate.com).
47
48
  - Supports [Gemnasium](https://gemnasium.com).
48
49
  - Supports [Travis CI](http://travis-ci.org).
50
+ - Supports [Patreon](https://www.patreon.com).
49
51
  - Provides the ability to open the source code of any gem within your favorite editor.
50
52
  - Provides the ability to read the documentation of any gem within your default browser.
51
53
  - Adds commonly needed [README](README.md), [CHANGELOG](CHANGELOG.md), [CONTRIBUTING](CONTRIBUTING.md),
52
- [LICENSE](LICENSE.md), etc. template files.
54
+ [CODE OF CONDUCT](CODE_OF_CONDUCT.md), [LICENSE](LICENSE.md), etc. documentation.
53
55
 
54
56
  # Requirements
55
57
 
56
- 0. A UNIX-based system.
57
- 0. [MRI 2.x.x](http://www.ruby-lang.org).
58
- 0. [RubyGems](http://rubygems.org).
59
- 0. [Bundler](https://github.com/carlhuda/bundler).
58
+ 0. A UNIX-based system
59
+ 0. [MRI 2.x.x](http://www.ruby-lang.org)
60
+ 0. [RubyGems](http://rubygems.org)
61
+ 0. [Bundler](https://github.com/carlhuda/bundler)
60
62
 
61
63
  # Setup
62
64
 
@@ -74,37 +76,60 @@ For an insecure install, type the following (not recommended):
74
76
 
75
77
  You can configure common settings for future gem builds by creating the following file:
76
78
 
77
- ~/.gemsmith/settings.yml
78
-
79
- ...using the following settings (for example):
80
-
81
- ---
82
- :author_name: Joe Smith
83
- :author_email: joe@smithware.com
84
- :author_url: https://www.smithware.com
85
- :company_name: Smithware
86
-
87
- If no options are configured, then the defaults are as follows:
88
-
89
- gem_platform: Gem::Platform::RUBY
90
- gem_private_key: ~/.ssh/gem-private.pem
91
- gem_public_key: ~/.ssh/gem-public.pem
92
- author_name: <git name>
93
- author_email: <git email>
94
- author_url: https://www.unknown.com
95
- gem_url: <author URL>
96
- company_name: <author name>
97
- company_url: <author URL>
98
- github_user: <github user>
99
- year: <current year>
100
- ruby_version: 2.2.0
101
- rails_version: 4.2
79
+ ~/.gemsmithrc
80
+
81
+ ...using the following settings (as a simple example):
82
+
83
+ :author:
84
+ :name: "Joe Smith"
85
+ :email: "joe@example.com"
86
+ :url: "https://www.example.com"
87
+ :organization:
88
+ :name: "ExampleSoft"
89
+ :url: "https://www.example.com"
90
+
91
+ The following defaults are used when no options are configured:
92
+
93
+ :year: <current year>
94
+ :github_user: <git config GitHub user>
95
+ :gem:
96
+ :platform: "Gem::Platform::RUBY"
97
+ :home_url: ""
98
+ :license: "MIT"
99
+ :private_key: "~/.ssh/gem-private.pem"
100
+ :public_key: "~/.ssh/gem-public.pem"
101
+ :author:
102
+ :name: <git config user name>
103
+ :email: <git config user email>
104
+ :url: ""
105
+ :organization:
106
+ :name: ""
107
+ :url: ""
108
+ :versions:
109
+ :ruby: <current Ruby version>
110
+ :rails: "4.2"
111
+ :create:
112
+ :cli: false
113
+ :rails: false
114
+ :security: true
115
+ :pry: true
116
+ :guard: true
117
+ :rspec: true
118
+ :rubocop: true
119
+ :code_climate: true
120
+ :gemnasium: true
121
+ :travis: true
122
+ :patreon: true
123
+
124
+ While Gemsmith is fully customizable, please keep in mind that these are *global* settings and, once set, will affect
125
+ all future gem creations. Further customization is also provided via the CLI for a customizable experience per gem if
126
+ necessary.
102
127
 
103
128
  # Usage
104
129
 
105
130
  ## Command Line Interface (CLI)
106
131
 
107
- From the command line, type: gemsmith help
132
+ From the command line, type: `gemsmith --help`
108
133
 
109
134
  gemsmith -c, [create=CREATE] # Create new gem.
110
135
  gemsmith -e, [--edit] # Edit Gemsmith settings in default editor.
@@ -113,9 +138,9 @@ From the command line, type: gemsmith help
113
138
  gemsmith -r, [read=READ] # Open a gem in default browser.
114
139
  gemsmith -v, [--version] # Show Gemsmith version.
115
140
 
116
- For more gem creation options, type: gemsmith help create
141
+ For more gem creation options, type: `gemsmith --help --create`
117
142
 
118
- -b, [--bin], [--no-bin] # Add binary support.
143
+ -c, [--cli], [--no-cli] # Add CLI support.
119
144
  -r, [--rails], [--no-rails] # Add Rails support.
120
145
  -S, [--security], [--no-security] # Add security support.
121
146
  # Default: true
@@ -127,35 +152,45 @@ For more gem creation options, type: gemsmith help create
127
152
  # Default: true
128
153
  -R, [--rubocop], [--no-rubocop] # Add Rubocop support.
129
154
  # Default: true
130
- -c, [--code-climate], [--no-code-climate] # Add Code Climate support.
155
+ -C, [--code-climate], [--no-code-climate] # Add Code Climate support.
131
156
  # Default: true
132
157
  -G, [--gemnasium], [--no-gemnasium] # Add Gemnasium support.
133
158
  # Default: true
134
159
  -t, [--travis], [--no-travis] # Add Travis CI support.
135
160
  # Default: true
161
+ -P, [--patreon], [--no-patreon] # Add Patreon support.
162
+ # Default: true
136
163
 
137
164
  ## Rake
138
165
 
139
166
  Once a gem skeleton has been created, the following tasks are available within the project via Bundler (i.e. rake -T):
140
167
 
141
- rake build # Build example-0.1.0.gem into the pkg directory
168
+ rake build # Build gemsmith-6.0.0.gem into the pkg directory
142
169
  rake clean # Clean gem artifacts
143
- rake install # Build and install example-0.1.0.gem into system gems
144
- rake install:local # Build and install example-0.1.0.gem into system gems without network access
145
- rake publish # Build, tag v0.1.0 (signed), and push example-0.1.0.gem to RubyGems
146
- rake readme:toc # Update README Table of Contents
147
- rake release # Create tag v0.1.0 and build and push example-0.1.0.gem to Rubygems
170
+ rake doc # Update README (table of contents)
171
+ rake install # Build and install gemsmith-6.0.0.gem into system gems
172
+ rake install:local # Build and install gemsmith-6.0.0.gem into system gems without network access
173
+ rake publish # Build, tag v6.0.0 (signed), and push gemsmith-6.0.0.gem to RubyGems
174
+ rake release # Create tag v6.0.0 and build and push gemsmith-6.0.0.gem to Rubygems
148
175
  rake rubocop # Run RuboCop
149
176
  rake rubocop:auto_correct # Auto-correct RuboCop offenses
150
177
  rake spec # Run RSpec code examples
151
178
 
179
+ Run `bundle exec rake` to run everything (includes all specs and code quality checks).
180
+
152
181
  ## Upgrades
153
182
 
154
- For those upgrading from Gemsmith 5.3.0 and wanting to use the new Rake tasks, do the following:
183
+ For those upgrading from Gemsmith 5.6.0 please be aware of the following changes:
155
184
 
156
- - Edit your `gemspec` and add the following dependency: `spec.add_development_dependency "gemsmith"`.
157
- - Edit your `Rakefile` and remove the Bundler requirement `require "bundler/gem_tasks"` and replace it with
158
- the Gemsmith tasks: `require "gemsmith/rake/setup"`. Don't worry, this includes the Bundler tasks too.
185
+ - Move your `~/.gemsmith/settings.yml` settings to the new `~/.gemsmithrc` file. Refer to the Setup documentation
186
+ mentioned above for details.
187
+ - The `--cli/-c` create option has been replaced with the `--bin/-b` create option.
188
+ - The `--code-climate` create option shortcut is now `-C` instead of `-c`.
189
+ - [Tocer](https://github.com/bkuhlmann/tocer) has replaced [DocToc](https://github.com/thlorenz/doctoc) as a pure Ruby
190
+ implementation for generating README table of contents and removing the dependency on NPM.
191
+ - The `rake readme:toc` task has been replaced with `rake doc`.
192
+ - Using Rake to build or publish a gem will fail if uncommitted Git changes are detected helping to prevent you
193
+ from publishing a gem with missing changes.
159
194
 
160
195
  # Tests
161
196
 
@@ -202,8 +237,8 @@ To create a certificate for your gems, run the following:
202
237
  gem cert --build you@example.com
203
238
  chmod 600 gem-*.pem
204
239
 
205
- The resulting *.pem keys can be referenced via the *gem_private_key- and *gem_public_key- settings mentioned in the
206
- Setup documentation.
240
+ The resulting `*.pem` key files can be referenced via the `:private_key:` and `:public_key:` keys within the
241
+ `~/.gemsmithrc` file.
207
242
 
208
243
  To learn more about gem certificates, read the following:
209
244
 
@@ -213,9 +248,10 @@ To learn more about gem certificates, read the following:
213
248
 
214
249
  # Promotion
215
250
 
216
- Once your gem is released, you might like to let the world know about the new awesomeness. Here are several resources:
251
+ Once your gem is released, you might want to let the world know about your awesomeness. Here are several resources:
217
252
 
218
253
  - [How to Spread the Word About Your Code](https://hacks.mozilla.org/2013/05/how-to-spread-the-word-about-your-code)
254
+ - [Ruby Green News](http://greenruby.org)
219
255
  - [Ruby Toolbox](https://www.ruby-toolbox.com)
220
256
  - [RubyFlow](http://www.rubyflow.com)
221
257
  - [The Ruby Show](http://rubyshow.com)
data/lib/gemsmith.rb CHANGED
@@ -1,2 +1 @@
1
1
  require "gemsmith/identity"
2
- require "gemsmith/kit"
@@ -0,0 +1,24 @@
1
+ module Gemsmith
2
+ module Aids
3
+ # Parses a raw string into a valid gem and/or class name which can be used to construct gem skeletons
4
+ # and related Ruby objects.
5
+ class Gem
6
+ def initialize string = "unknown", util: Thor::Util
7
+ @string = string
8
+ @util = util
9
+ end
10
+
11
+ def name
12
+ @name ||= util.snake_case(string).tr(" ", "_").tr "-", "_"
13
+ end
14
+
15
+ def klass
16
+ @klass ||= util.camel_case name
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :string, :util
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ module Gemsmith
2
+ module Aids
3
+ # A thin wrapper to Git.
4
+ class Git
5
+ def self.config_value key
6
+ `git config #{key}`.chomp
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,41 @@
1
+ require "open3"
2
+
3
+ module Gemsmith
4
+ module Aids
5
+ # A convenience aid to the Gem::Specification object.
6
+ class Spec
7
+ def initialize specification: ::Gem::Specification, shell: Open3
8
+ @specification = specification
9
+ @shell = shell
10
+ end
11
+
12
+ def editor
13
+ ENV["EDITOR"]
14
+ end
15
+
16
+ def open spec = nil
17
+ return unless spec
18
+ shell.capture2 editor, spec.full_gem_path
19
+ end
20
+
21
+ def read spec = nil
22
+ return unless spec
23
+ return if spec.homepage.nil? || spec.homepage.empty?
24
+
25
+ shell.capture2 "open", spec.homepage
26
+ end
27
+
28
+ def find name, version
29
+ specification.find_by_name name, version
30
+ end
31
+
32
+ def find_all name
33
+ specification.find_all_by_name name
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :specification, :shell
39
+ end
40
+ end
41
+ end
data/lib/gemsmith/cli.rb CHANGED
@@ -2,8 +2,9 @@ require "yaml"
2
2
  require "thor"
3
3
  require "thor/actions"
4
4
  require "thor_plus/actions"
5
- require "gemsmith/cli_options"
6
- require "gemsmith/cli_helpers"
5
+ require "gemsmith/aids/gem"
6
+ require "gemsmith/aids/git"
7
+ require "gemsmith/aids/spec"
7
8
  require "gemsmith/skeletons/base_skeleton"
8
9
  require "gemsmith/skeletons/bundler_skeleton"
9
10
  require "gemsmith/skeletons/cli_skeleton"
@@ -11,19 +12,21 @@ require "gemsmith/skeletons/documentation_skeleton"
11
12
  require "gemsmith/skeletons/gem_skeleton"
12
13
  require "gemsmith/skeletons/git_skeleton"
13
14
  require "gemsmith/skeletons/guard_skeleton"
15
+ require "gemsmith/skeletons/pry_skeleton"
14
16
  require "gemsmith/skeletons/rails_skeleton"
15
17
  require "gemsmith/skeletons/rake_skeleton"
16
18
  require "gemsmith/skeletons/rspec_skeleton"
17
19
  require "gemsmith/skeletons/rubocop_skeleton"
18
20
  require "gemsmith/skeletons/ruby_skeleton"
19
21
  require "gemsmith/skeletons/travis_skeleton"
22
+ require "gemsmith/cli_helpers"
23
+ require "gemsmith/configuration"
20
24
 
21
25
  module Gemsmith
22
26
  # The Command Line Interface (CLI) for the gem.
23
27
  class CLI < Thor
24
28
  include Thor::Actions
25
29
  include ThorPlus::Actions
26
- include CLIOptions
27
30
  include CLIHelpers
28
31
 
29
32
  package_name Gemsmith::Identity.version_label
@@ -44,6 +47,7 @@ module Gemsmith
44
47
  Skeletons::RspecSkeleton,
45
48
  Skeletons::RubocopSkeleton,
46
49
  Skeletons::GuardSkeleton,
50
+ Skeletons::PrySkeleton,
47
51
  Skeletons::TravisSkeleton,
48
52
  Skeletons::BundlerSkeleton,
49
53
  Skeletons::GitSkeleton
@@ -53,29 +57,29 @@ module Gemsmith
53
57
  # Initialize.
54
58
  def initialize args = [], options = {}, config = {}
55
59
  super args, options, config
56
- @settings_file = File.join ENV["HOME"], ".gemsmith", "settings.yml"
57
- @settings = load_yaml @settings_file
58
- @template_options = {}
60
+ @configuration = Configuration.new
61
+ @spec_aid = Aids::Spec.new
59
62
  end
60
63
 
61
64
  desc "-c, [create=CREATE]", "Create new gem."
62
65
  map %w(-c --create) => :create
63
- method_option :bin, aliases: "-b", desc: "Add binary support.", type: :boolean, default: false
66
+ method_option :cli, aliases: "-c", desc: "Add CLI support.", type: :boolean, default: false
64
67
  method_option :rails, aliases: "-r", desc: "Add Rails support.", type: :boolean, default: false
65
68
  method_option :security, aliases: "-S", desc: "Add security support.", type: :boolean, default: true
66
69
  method_option :pry, aliases: "-p", desc: "Add Pry support.", type: :boolean, default: true
67
70
  method_option :guard, aliases: "-g", desc: "Add Guard support.", type: :boolean, default: true
68
71
  method_option :rspec, aliases: "-s", desc: "Add RSpec support.", type: :boolean, default: true
69
72
  method_option :rubocop, aliases: "-R", desc: "Add Rubocop support.", type: :boolean, default: true
70
- method_option :code_climate, aliases: "-c", desc: "Add Code Climate support.", type: :boolean, default: true
73
+ method_option :code_climate, aliases: "-C", desc: "Add Code Climate support.", type: :boolean, default: true
71
74
  method_option :gemnasium, aliases: "-G", desc: "Add Gemnasium support.", type: :boolean, default: true
72
75
  method_option :travis, aliases: "-t", desc: "Add Travis CI support.", type: :boolean, default: true
76
+ method_option :patreon, aliases: "-P", desc: "Add Patreon support.", type: :boolean, default: true
73
77
  def create name
74
78
  say
75
79
  info "Creating gem..."
76
80
 
77
- initialize_template_options name, options
78
- self.class.skeletons.each { |skeleton| skeleton.create self }
81
+ setup_configuration name, options
82
+ self.class.skeletons.each { |skeleton| skeleton.create self, configuration: configuration }
79
83
 
80
84
  info "Gem created."
81
85
  say
@@ -96,7 +100,8 @@ module Gemsmith
96
100
  desc "-e, [--edit]", "Edit #{Gemsmith::Identity.label} settings in default editor."
97
101
  map %w(-e --edit) => :edit
98
102
  def edit
99
- `#{editor} #{@settings_file}`
103
+ info "Editing: #{configuration.file_path}..."
104
+ `#{spec_aid.editor} #{configuration.file_path}`
100
105
  end
101
106
 
102
107
  desc "-v, [--version]", "Show #{Gemsmith::Identity.label} version."
@@ -110,5 +115,15 @@ module Gemsmith
110
115
  def help task = nil
111
116
  say && super
112
117
  end
118
+
119
+ private
120
+
121
+ attr_reader :configuration, :spec_aid
122
+
123
+ def setup_configuration name, options
124
+ gem = Aids::Gem.new name
125
+ @configuration = Configuration.new gem_name: gem.name, gem_class: gem.klass
126
+ options.each { |key, value| configuration.public_send "create_#{key}=", value }
127
+ end
113
128
  end
114
129
  end
@@ -1,97 +1,48 @@
1
1
  module Gemsmith
2
- # Command Line Interface (CLI) helpers that aid the CLI class. These are extracted to a module
3
- # in order to not clutter up the main CLI object.
2
+ # Command Line Interface (CLI) helpers for the CLI class.
4
3
  module CLIHelpers
5
- # Answers default editor.
6
- # NOTE: This will be replaced by the Thor+ gem in the future.
7
- def editor
8
- ENV["EDITOR"]
4
+ def gem_name
5
+ configuration.gem_name
9
6
  end
10
7
 
11
- # Answers the gem name (snake case).
12
- # ==== Parameters
13
- # * +name+ - Optional. The gem name. Default: nil
14
- def gem_name name = nil
15
- @gem_name ||= Thor::Util.snake_case name
8
+ def gem_class
9
+ configuration.gem_class
16
10
  end
17
11
 
18
- # Answers the gem class (camel case).
19
- # ==== Parameters
20
- # * +name+ - Optional. The gem class. Default: nil
21
- def gem_class name = nil
22
- @gem_class ||= Thor::Util.camel_case name
23
- end
24
-
25
- # Answers all gem template options.
26
- def template_options
27
- @template_options
12
+ def rails_version
13
+ configuration.rails_version
28
14
  end
29
15
 
30
16
  module_function
31
17
 
32
- # Converts hash keys from strings to symbols (if any).
33
- # ===== Parameters
34
- # * +options+ - Optional. The hash to convert. Default: {}
35
- def enforce_symbol_keys options = {}
36
- options.each.with_object({}) { |(key, value), hash| hash[key.to_sym] = value }
37
- end
38
-
39
- # Prints currently installed gem name and version information.
40
- # ===== Parameters
41
- # * +gems+ - Required. The array of gem names (i.e. gem specifications).
42
18
  def print_gems gems
43
- say "Multiple versions found:"
44
- gems.each.with_index do |spec, index|
45
- say "#{index + 1}. #{spec.name} #{spec.version.version}"
46
- end
19
+ say "Multiple versions found:\n\n"
20
+ gems.each.with_index { |spec, index| say "#{index + 1}. #{spec.name} #{spec.version.version}" }
21
+ say "q. Quit.\n\n"
47
22
  end
48
23
 
49
- # Picks a gem specification for processing.
50
- # ===== Parameters
51
- # * +gems+ - Required. The array of gem specifications.
52
- # * +name+ - Required. The gem name to search for.
53
24
  def pick_gem gems, name
54
- result = ask "Please pick one (or type 'q' to quit):"
25
+ answer = ask "Enter selection:"
26
+ return if answer == "q"
55
27
 
56
- return if result == "q" # Exit early.
57
-
58
- if (1..gems.size).include?(result.to_i)
59
- Gem::Specification.find_by_name name, gems[result.to_i - 1].version.version
28
+ if (1..gems.size).include?(answer.to_i)
29
+ spec_aid.find name, gems[answer.to_i - 1].version.version
60
30
  else
61
- error "Invalid option: #{result}"
62
- nil
31
+ error "Invalid option: #{answer}"
63
32
  end
64
33
  end
65
34
 
66
- # Opens selected gem within default editor.
67
- # ===== Parameters
68
- # * +spec+ - Required. The gem specification.
69
- def open_gem spec
70
- `#{editor} #{spec.full_gem_path}` if spec
71
- end
72
-
73
- # Opens selected gem within default browser.
74
- # ===== Parameters
75
- # * +spec+ - Required. The gem specification.
76
- def read_gem spec
77
- `open #{spec.homepage}` if spec
78
- end
79
-
80
- # Processes a gem for given name and command.
81
- # ===== Parameters
82
- # * +name+ - Required. The gem name.
83
- # * +command+ - Required. The command to process the gem.
84
- def process_gem name, command
85
- specs = Gem::Specification.find_all_by_name name
35
+ def process_gem name, method
36
+ specs = spec_aid.find_all name
86
37
 
87
38
  case
88
39
  when specs.size == 1
89
- send "#{command}_gem", specs.first
40
+ spec_aid.send method, specs.first
90
41
  when specs.size > 1
91
42
  print_gems specs
92
- send "#{command}_gem", pick_gem(specs, name)
43
+ spec_aid.send method, pick_gem(specs, name)
93
44
  else
94
- say "Unable to find gem: #{name}"
45
+ error "Unable to find gem: #{name}."
95
46
  end
96
47
  end
97
48
  end