gemsmith 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{LICENSE.rdoc → LICENSE.md} +1 -1
- data/README.md +154 -0
- data/lib/gemsmith.rb +2 -2
- data/lib/gemsmith/cli.rb +32 -131
- data/lib/gemsmith/cli_helpers.rb +90 -0
- data/lib/gemsmith/cli_options.rb +94 -0
- data/lib/gemsmith/skeletons/base_skeleton.rb +35 -0
- data/lib/gemsmith/skeletons/cli_skeleton.rb +10 -0
- data/lib/gemsmith/skeletons/default_skeleton.rb +21 -0
- data/lib/gemsmith/skeletons/documentation_skeleton.rb +12 -0
- data/lib/gemsmith/skeletons/git_skeleton.rb +13 -0
- data/lib/gemsmith/skeletons/rails_skeleton.rb +51 -0
- data/lib/gemsmith/skeletons/rspec_skeleton.rb +17 -0
- data/lib/gemsmith/skeletons/travis_skeleton.rb +9 -0
- data/lib/gemsmith/templates/{gem.gemspec.tmp → %gem_name%/%gem_name%.gemspec.tt} +4 -3
- data/lib/gemsmith/templates/{gitignore.tmp → %gem_name%/.gitignore.tt} +2 -1
- data/lib/gemsmith/templates/{rspec.tmp → %gem_name%/.rspec.tt} +0 -0
- data/lib/gemsmith/templates/%gem_name%/.ruby-version.tt +1 -0
- data/lib/gemsmith/templates/{travis.yml.tmp → %gem_name%/.travis.yml.tt} +0 -2
- data/lib/gemsmith/templates/{CHANGELOG.rdoc.tmp → %gem_name%/CHANGELOG.md.tt} +1 -1
- data/lib/gemsmith/templates/{CONTRIBUTING.md.tmp → %gem_name%/CONTRIBUTING.md.tt} +0 -0
- data/lib/gemsmith/templates/{Gemfile.tmp → %gem_name%/Gemfile.tt} +0 -0
- data/lib/gemsmith/templates/{LICENSE.rdoc.tmp → %gem_name%/LICENSE.md.tt} +1 -1
- data/lib/gemsmith/templates/%gem_name%/README.md.tt +59 -0
- data/lib/gemsmith/templates/{Rakefile.tmp → %gem_name%/Rakefile.tt} +0 -0
- data/lib/gemsmith/templates/{bin/gem.tmp → %gem_name%/bin/%gem_name%.tt} +0 -0
- data/lib/gemsmith/templates/{gemfiles/rails-3.2.x.gemfile.tmp → %gem_name%/gemfiles/rails-3.2.x.gemfile.tt} +1 -1
- data/lib/gemsmith/templates/%gem_name%/lib/%gem_name%.rb.tt +33 -0
- data/lib/gemsmith/templates/{lib/gem/action_controller/class_methods.rb.tmp → %gem_name%/lib/%gem_name%/action_controller/class_methods.rb.tt} +2 -2
- data/lib/gemsmith/templates/{lib/gem/action_controller/instance_methods.rb.tmp → %gem_name%/lib/%gem_name%/action_controller/instance_methods.rb.tt} +0 -0
- data/lib/gemsmith/templates/{lib/gem/action_view/instance_methods.rb.tmp → %gem_name%/lib/%gem_name%/action_view/instance_methods.rb.tt} +0 -0
- data/lib/gemsmith/templates/{lib/gem/active_record/class_methods.rb.tmp → %gem_name%/lib/%gem_name%/active_record/class_methods.rb.tt} +2 -2
- data/lib/gemsmith/templates/{lib/gem/active_record/instance_methods.rb.tmp → %gem_name%/lib/%gem_name%/active_record/instance_methods.rb.tt} +0 -0
- data/lib/gemsmith/templates/{lib/gem/cli.rb.tmp → %gem_name%/lib/%gem_name%/cli.rb.tt} +1 -1
- data/lib/gemsmith/templates/{lib/gem/version.rb.tmp → %gem_name%/lib/%gem_name%/version.rb.tt} +0 -0
- data/lib/gemsmith/templates/{lib/generators/gem/install/USAGE.tmp → %gem_name%/lib/generators/%gem_name%/install/USAGE.tt} +0 -0
- data/lib/gemsmith/templates/{lib/generators/gem/install/install_generator.rb.tmp → %gem_name%/lib/generators/%gem_name%/install/install_generator.rb.tt} +0 -0
- data/lib/gemsmith/templates/{lib/generators/gem/upgrade/USAGE.tmp → %gem_name%/lib/generators/%gem_name%/upgrade/USAGE.tt} +0 -0
- data/lib/gemsmith/templates/{lib/generators/gem/upgrade/upgrade_generator.rb.tmp → %gem_name%/lib/generators/%gem_name%/upgrade/upgrade_generator.rb.tt} +0 -0
- data/lib/gemsmith/templates/{spec/gem_spec.rb.tmp → %gem_name%/spec/%gem_name%_spec.rb.tt} +0 -0
- data/lib/gemsmith/templates/{spec/spec_helper.rb.tmp → %gem_name%/spec/spec_helper.rb.tt} +2 -1
- data/lib/gemsmith/version.rb +1 -1
- metadata +61 -40
- data/CHANGELOG.rdoc +0 -134
- data/README.rdoc +0 -133
- data/lib/gemsmith/templates/README.rdoc.tmp +0 -59
- data/lib/gemsmith/templates/gemfiles/rails-3.0.x.gemfile.tmp +0 -5
- data/lib/gemsmith/templates/gemfiles/rails-3.1.x.gemfile.tmp +0 -5
- data/lib/gemsmith/templates/lib/gem.rb.tmp +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 844ed51e2c822e23c4c5f2ec59783a872d56f86b
|
4
|
+
data.tar.gz: c4a454c20bb5f7085ba732d0a417b34419249395
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a96e1522f52d68759bd1c3d406e73532806d9298ce5ff541e460ff223e27a7baa5cc9e8daffcc1032909c66fb099869ee429b2faa1e01f9a949d2722277a5525
|
7
|
+
data.tar.gz: 6fd9d55827af7153afa0e40b21411f6b91785ac15a8ec832c92337845714346ea4a21e3bb3007185be150393e8756ee59b5d320c875bf9b4eaf595583975ecff
|
data/{LICENSE.rdoc → LICENSE.md}
RENAMED
data/README.md
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
# Overview
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/gemsmith.png)](http://badge.fury.io/rb/gemsmith)
|
4
|
+
[![Code Climate GPA](https://codeclimate.com/github/bkuhlmann/gemsmith.png)](https://codeclimate.com/github/bkuhlmann/gemsmith)
|
5
|
+
[![Travis CI Status](https://secure.travis-ci.org/bkuhlmann/gemsmith.png)](http://travis-ci.org/bkuhlmann/gemsmith)
|
6
|
+
|
7
|
+
Gemsmith allows you to easily craft new gems via the command line with custom settings (if desired). If you are
|
8
|
+
a fan of [Bundler](https://github.com/carlhuda/bundler), then you'll appreciate the additional capabilities of this
|
9
|
+
gem. Gemsmith is essentially an enhanced version of Bundler's gem building capabilities.
|
10
|
+
|
11
|
+
# Features
|
12
|
+
|
13
|
+
* Builds a gem skeleton with Bundler functionality in mind.
|
14
|
+
* Supports common settings that can be applied to new gem creations.
|
15
|
+
* Supports binary skeletons with [Thor](https://github.com/wycats/thor) command line functionality.
|
16
|
+
* Supports [Ruby on Rails](http://rubyonrails.org).
|
17
|
+
* Supports [RSpec](http://rspec.info).
|
18
|
+
* Supports [Pry](http://pryrepl.org).
|
19
|
+
* Supports [Guard](https://github.com/guard/guard).
|
20
|
+
* Supports [Code Climate](https://codeclimate.com).
|
21
|
+
* Supports [Travis CI](http://travis-ci.org) skeletons.
|
22
|
+
* Adds commonly needed README, CHANGELOG, LICENSE, etc. template files.
|
23
|
+
* Provides the ability to open any installed gem within your favorite editor.
|
24
|
+
|
25
|
+
# Requirements
|
26
|
+
|
27
|
+
1. A UNIX-based system.
|
28
|
+
2. [Ruby 2.0.x](http://www.ruby-lang.org).
|
29
|
+
3. [RubyGems](http://rubygems.org).
|
30
|
+
4. [Bundler](https://github.com/carlhuda/bundler).
|
31
|
+
|
32
|
+
# Setup
|
33
|
+
|
34
|
+
Type the following from the command line to install:
|
35
|
+
|
36
|
+
gem install gemsmith
|
37
|
+
|
38
|
+
You can configure common settings for future gem builds by creating the following file:
|
39
|
+
|
40
|
+
~/.gemsmith/settings.yml
|
41
|
+
|
42
|
+
...using the following settings (for example):
|
43
|
+
|
44
|
+
---
|
45
|
+
:author_name: Brooke Kuhlmann
|
46
|
+
:author_email: brooke@redalchemist.com
|
47
|
+
:author_url: http://www.redalchemist.com
|
48
|
+
:company_name: Red Alchemist
|
49
|
+
|
50
|
+
If no options are configured, then the defaults are as follows:
|
51
|
+
|
52
|
+
gem_platform: Gem::Platform::RUBY
|
53
|
+
author_name: <git name>
|
54
|
+
author_email: <git email>
|
55
|
+
author_url: https://www.unknown.com
|
56
|
+
gem_url: <author URL>
|
57
|
+
company_name: <author name>
|
58
|
+
company_url: <author URL>
|
59
|
+
github_user: <github user>
|
60
|
+
year: <current year>
|
61
|
+
ruby_version: 2.0.0
|
62
|
+
ruby_patch: p0
|
63
|
+
rails_version: 3.2.0
|
64
|
+
|
65
|
+
# Usage
|
66
|
+
|
67
|
+
From the command line, type: gemsmith help
|
68
|
+
|
69
|
+
gemsmith -c, [create=GEM_NAME] # Create new gem.
|
70
|
+
gemsmith -e, [edit] # Edit gem settings in default editor (assumes $EDITOR environment variable).
|
71
|
+
gemsmith -h, [help] # Show this message.
|
72
|
+
gemsmith -o, [open=NAME] # Opens gem in default editor (assumes $EDITOR environment variable).
|
73
|
+
gemsmith -r, [read=NAME] # Opens gem in default browser.
|
74
|
+
gemsmith -v, [version] # Show version.
|
75
|
+
|
76
|
+
For more gem creation options, type: gemsmith help create
|
77
|
+
|
78
|
+
-b, [--bin] # Add binary support.
|
79
|
+
-r, [--rails] # Add Rails support.
|
80
|
+
-p, [--pry] # Add Pry support.
|
81
|
+
# Default: true
|
82
|
+
-g, [--guard] # Add Guard support.
|
83
|
+
# Default: true
|
84
|
+
-s, [--rspec] # Add RSpec support.
|
85
|
+
# Default: true
|
86
|
+
-t, [--travis] # Add Travis CI support.
|
87
|
+
# Default: true
|
88
|
+
-c, [--code-climate] # Add Code Climate support.
|
89
|
+
# Default: true
|
90
|
+
|
91
|
+
Also, don't forget that once you have created your gem skeleton, the following rake tasks are also
|
92
|
+
available to you via Bundler (i.e. rake -T):
|
93
|
+
|
94
|
+
rake build # Build <gem>-<version>.gem into the pkg directory
|
95
|
+
rake install # Build and install <gem>-<version>.gem into system gems
|
96
|
+
rake release # Create tag v0.1.1 and build and push <gem>-<version>.gem to Rubygems
|
97
|
+
|
98
|
+
# Tests
|
99
|
+
|
100
|
+
To test, do the following:
|
101
|
+
|
102
|
+
0. cd to the gem root.
|
103
|
+
0. bundle install
|
104
|
+
0. bundle exec rspec spec
|
105
|
+
|
106
|
+
# Best Practices
|
107
|
+
|
108
|
+
0. [Semantic Versioning](http://semver.org)
|
109
|
+
0. [Best Practices While Cutting Gems](http://rubysource.com/crafting-rubies-best-practices-while-cutting-gems).
|
110
|
+
0. [Ruby on Rails Gem Packaging](http://weblog.rubyonrails.org/2009/9/1/gem-packaging-best-practices).
|
111
|
+
0. [Gem Activation and You: Part I](http://erik.hollensbe.org/2013/05/11/gem-activation-and-you)
|
112
|
+
0. [Gem Activation and You: Part II](http://erik.hollensbe.org/2013/05/15/gem-activation-and-you-part-2-bundler-and-binstubs)
|
113
|
+
0. [Why You Should Use a BSD Style License](http://www.freebsd.org/doc/en/articles/bsdl-gpl/article.html).
|
114
|
+
0. Add -w to the RUBYOPT environment variable when testing. [Details](http://avdi.org/devblog/2011/06/23/how-ruby-helps-you-fix-your-broken-code).
|
115
|
+
|
116
|
+
## When To Include a Railtie ([Crafting Rails Applications](http://pragprog.com/book/jvrails/crafting-rails-applications) - Page 93 by José Valim)
|
117
|
+
|
118
|
+
* "Your gem needs to perform a given task while or after the Rails application is initialized."
|
119
|
+
* "Your gem needs to change a configuration value, such as setting a generator."
|
120
|
+
* "Your gem must provide Rake tasks and generators in nondefault locations (the default location for the former is lib/tasks and lib/gen- erators or lib/rails/generators for the latter)."
|
121
|
+
* "You want your gem to provide configuration options to the appli- cation, such as config.my_gem.key # :value."
|
122
|
+
|
123
|
+
# Documentation
|
124
|
+
|
125
|
+
In order to make your gem easier to use and adopt by others, good documentation is always a plus. Consider submitting
|
126
|
+
your gem to RubyDocs[http://rubydoc.info] once your gem is released and available for use. RubyDocs supports both
|
127
|
+
RDoc and YARD formats.
|
128
|
+
|
129
|
+
# Promotion
|
130
|
+
|
131
|
+
Once your gem is released, you might like to let the world know about the new awesomeness. Here are several resources:
|
132
|
+
|
133
|
+
* [How to Spread the Word About Your Code](https://hacks.mozilla.org/2013/05/how-to-spread-the-word-about-your-code)
|
134
|
+
* [Ruby Toolbox](https://www.ruby-toolbox.com)
|
135
|
+
* [RubyFlow](http://www.rubyflow.com)
|
136
|
+
* [The Ruby Show](http://rubyshow.com)
|
137
|
+
* [Ruby 5](http://ruby5.envylabs.com)
|
138
|
+
|
139
|
+
# Contributions
|
140
|
+
|
141
|
+
Read CONTRIBUTING for details.
|
142
|
+
|
143
|
+
# Credits
|
144
|
+
|
145
|
+
Developed by [Brooke Kuhlmann](http://www.redalchemist.com) at [Red Alchemist](http://www.redalchemist.com).
|
146
|
+
|
147
|
+
# License
|
148
|
+
|
149
|
+
Copyright (c) 2011 [Red Alchemist](http://www.redalchemist.com).
|
150
|
+
Read the LICENSE for details.
|
151
|
+
|
152
|
+
# History
|
153
|
+
|
154
|
+
Read the CHANGELOG for details.
|
data/lib/gemsmith.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "gemsmith/version"
|
2
|
+
require "gemsmith/kit"
|
data/lib/gemsmith/cli.rb
CHANGED
@@ -2,22 +2,35 @@ 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"
|
7
|
+
require "gemsmith/skeletons/base_skeleton"
|
8
|
+
require "gemsmith/skeletons/default_skeleton"
|
9
|
+
require "gemsmith/skeletons/documentation_skeleton"
|
10
|
+
require "gemsmith/skeletons/cli_skeleton"
|
11
|
+
require "gemsmith/skeletons/rails_skeleton"
|
12
|
+
require "gemsmith/skeletons/rspec_skeleton"
|
13
|
+
require "gemsmith/skeletons/travis_skeleton"
|
14
|
+
require "gemsmith/skeletons/git_skeleton"
|
5
15
|
|
6
16
|
module Gemsmith
|
7
17
|
class CLI < Thor
|
8
18
|
include Thor::Actions
|
9
19
|
include ThorPlus::Actions
|
20
|
+
include CLIOptions
|
21
|
+
include CLIHelpers
|
10
22
|
|
11
23
|
# Overwrites the Thor template source root.
|
12
24
|
def self.source_root
|
13
25
|
File.expand_path File.join(File.dirname(__FILE__), "templates")
|
14
26
|
end
|
15
|
-
|
27
|
+
|
16
28
|
# Initialize.
|
17
29
|
def initialize args = [], options = {}, config = {}
|
18
30
|
super args, options, config
|
19
31
|
@settings_file = File.join ENV["HOME"], ".gemsmith", "settings.yml"
|
20
32
|
@settings = load_yaml @settings_file
|
33
|
+
@template_options = {}
|
21
34
|
end
|
22
35
|
|
23
36
|
desc "-c, [create=GEM_NAME]", "Create new gem."
|
@@ -32,105 +45,32 @@ module Gemsmith
|
|
32
45
|
def create name
|
33
46
|
say
|
34
47
|
info "Creating gem..."
|
35
|
-
|
36
|
-
# Initialize options.
|
37
|
-
template_options = build_template_options name, @settings, options
|
38
|
-
gem_name = template_options[:gem_name]
|
39
|
-
|
40
|
-
# Configure templates.
|
41
|
-
target_path = File.join Dir.pwd, gem_name
|
42
|
-
|
43
|
-
# Default templates.
|
44
|
-
template "README.rdoc.tmp", File.join(target_path, "README.rdoc"), template_options
|
45
|
-
template "CONTRIBUTING.md.tmp", File.join(target_path, "CONTRIBUTING.md"), template_options
|
46
|
-
template "LICENSE.rdoc.tmp", File.join(target_path, "LICENSE.rdoc"), template_options
|
47
|
-
template "CHANGELOG.rdoc.tmp", File.join(target_path, "CHANGELOG.rdoc"), template_options
|
48
|
-
template "Gemfile.tmp", File.join(target_path, "Gemfile"), template_options
|
49
|
-
template "Rakefile.tmp", File.join(target_path, "Rakefile"), template_options
|
50
|
-
template "gitignore.tmp", File.join(target_path, ".gitignore"), template_options
|
51
|
-
template "gem.gemspec.tmp", File.join(target_path, "#{gem_name}.gemspec"), template_options
|
52
|
-
template File.join("lib", "gem.rb.tmp"), File.join(target_path, "lib", "#{gem_name}.rb"), template_options
|
53
|
-
template File.join("lib", "gem", "version.rb.tmp"), File.join(target_path, "lib", gem_name, "version.rb"), template_options
|
54
|
-
|
55
|
-
# Binary (optional).
|
56
|
-
if template_options[:bin]
|
57
|
-
template File.join("bin", "gem.tmp"), File.join(target_path, "bin", gem_name), template_options
|
58
|
-
template File.join("lib", "gem", "cli.rb.tmp"), File.join(target_path, "lib", gem_name, "cli.rb"), template_options
|
59
|
-
end
|
60
|
-
|
61
|
-
# Ruby on Rails (optional).
|
62
|
-
if template_options[:rails]
|
63
|
-
# ActionController
|
64
|
-
template File.join("lib", "gem", "action_controller", "class_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "action_controller", "class_methods.rb"), template_options
|
65
|
-
template File.join("lib", "gem", "action_controller", "instance_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "action_controller", "instance_methods.rb"), template_options
|
66
|
-
# ActionView
|
67
|
-
template File.join("lib", "gem", "action_view", "instance_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "action_view", "instance_methods.rb"), template_options
|
68
|
-
# ActiveRecord
|
69
|
-
template File.join("lib", "gem", "active_record", "class_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "active_record", "class_methods.rb"), template_options
|
70
|
-
template File.join("lib", "gem", "active_record", "instance_methods.rb.tmp"), File.join(target_path, "lib", gem_name, "active_record", "instance_methods.rb"), template_options
|
71
|
-
# Generators
|
72
|
-
empty_directory File.join(target_path, "lib", "generators", gem_name, "templates")
|
73
|
-
template File.join("lib", "generators", "gem", "install", "install_generator.rb.tmp"), File.join(target_path, "lib", "generators", gem_name, "install", "install_generator.rb"), template_options
|
74
|
-
template File.join("lib", "generators", "gem", "install", "USAGE.tmp"), File.join(target_path, "lib", "generators", gem_name, "install", "USAGE"), template_options
|
75
|
-
template File.join("lib", "generators", "gem", "upgrade", "upgrade_generator.rb.tmp"), File.join(target_path, "lib", "generators", gem_name, "upgrade", "upgrade_generator.rb"), template_options
|
76
|
-
template File.join("lib", "generators", "gem", "upgrade", "USAGE.tmp"), File.join(target_path, "lib", "generators", gem_name, "upgrade", "USAGE"), template_options
|
77
|
-
# Travis CI (optional).
|
78
|
-
if template_options[:travis]
|
79
|
-
template File.join("gemfiles", "rails-3.0.x.gemfile.tmp"), File.join(target_path, "gemfiles", "rails-3.0.x.gemfile"), template_options
|
80
|
-
template File.join("gemfiles", "rails-3.1.x.gemfile.tmp"), File.join(target_path, "gemfiles", "rails-3.1.x.gemfile"), template_options
|
81
|
-
template File.join("gemfiles", "rails-3.2.x.gemfile.tmp"), File.join(target_path, "gemfiles", "rails-3.2.x.gemfile"), template_options
|
82
|
-
end
|
83
|
-
end
|
84
48
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
49
|
+
initialize_template_options name, options
|
50
|
+
Skeletons::DefaultSkeleton.run self
|
51
|
+
Skeletons::DocumentationSkeleton.run self
|
52
|
+
Skeletons::CLISkeleton.run(self) if template_options[:bin]
|
53
|
+
Skeletons::RailsSkeleton.run(self) if template_options[:rails]
|
54
|
+
Skeletons::RspecSkeleton.run(self) if template_options[:rspec]
|
55
|
+
Skeletons::TravisSkeleton.run(self) if template_options[:travis]
|
56
|
+
Skeletons::GitSkeleton.run self
|
91
57
|
|
92
|
-
# Travis CI (optional).
|
93
|
-
if template_options[:travis]
|
94
|
-
template "travis.yml.tmp", File.join(target_path, ".travis.yml"), template_options
|
95
|
-
end
|
96
|
-
|
97
|
-
# Git
|
98
|
-
Dir.chdir(target_path) do
|
99
|
-
`git init`
|
100
|
-
`git add .`
|
101
|
-
`git commit -a -n -m "Gemsmith skeleton created."`
|
102
|
-
end
|
103
|
-
|
104
58
|
info "Gem created."
|
105
59
|
say
|
106
60
|
end
|
107
|
-
|
61
|
+
|
108
62
|
desc "-o, [open=NAME]", "Opens gem in default editor (assumes $EDITOR environment variable)."
|
109
63
|
map "-o" => :open
|
110
64
|
def open name
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
say "#{index + 1}. #{spec.name} #{spec.version.version}"
|
119
|
-
end
|
120
|
-
result = ask "Please pick one (or type 'q' to quit):"
|
121
|
-
unless result == 'q'
|
122
|
-
if (1..specs.size).include?(result.to_i)
|
123
|
-
spec = Gem::Specification.find_by_name(name, specs[result.to_i - 1].version.version)
|
124
|
-
`$EDITOR #{spec.full_gem_path}`
|
125
|
-
else
|
126
|
-
error "Invalid option: #{result}"
|
127
|
-
end
|
128
|
-
end
|
129
|
-
else
|
130
|
-
say "Unable to find gem: #{name}"
|
131
|
-
end
|
65
|
+
process_gem name, "open"
|
66
|
+
end
|
67
|
+
|
68
|
+
desc "-r, [read=NAME]", "Opens gem in default browser."
|
69
|
+
map "-r" => :read
|
70
|
+
def read name
|
71
|
+
process_gem name, "read"
|
132
72
|
end
|
133
|
-
|
73
|
+
|
134
74
|
desc "-e, [edit]", "Edit gem settings in default editor (assumes $EDITOR environment variable)."
|
135
75
|
map "-e" => :edit
|
136
76
|
def edit
|
@@ -142,49 +82,10 @@ module Gemsmith
|
|
142
82
|
def version
|
143
83
|
say "Gemsmith " + VERSION
|
144
84
|
end
|
145
|
-
|
85
|
+
|
146
86
|
desc "-h, [help]", "Show this message."
|
147
87
|
def help task = nil
|
148
88
|
say and super
|
149
89
|
end
|
150
|
-
|
151
|
-
private
|
152
|
-
|
153
|
-
# Builds template options with default and/or custom settings (where the custom
|
154
|
-
# settings trump default settings).
|
155
|
-
# ==== Parameters
|
156
|
-
# * +gem_name+ - Required. The gem name.
|
157
|
-
# * +settings+ - Optional. The custom settings. Default: {}.
|
158
|
-
# * +options+ - Optional. Additional command line options. Default: {}.
|
159
|
-
def build_template_options gem_name, settings = {}, options = {}
|
160
|
-
gem_name = Thor::Util.snake_case gem_name
|
161
|
-
gem_class = Thor::Util.camel_case gem_name
|
162
|
-
author_name = settings[:author_name] || Gemsmith::Kit.git_config_value("user.name") || "TODO: Add full name here."
|
163
|
-
author_email = settings[:author_email] || Gemsmith::Kit.git_config_value("user.email") || "TODO: Add email address here."
|
164
|
-
author_url = settings[:author_url] || "https://www.unknown.com"
|
165
|
-
{
|
166
|
-
gem_name: gem_name,
|
167
|
-
gem_class: gem_class,
|
168
|
-
gem_platform: (settings[:gem_platform] || "Gem::Platform::RUBY"),
|
169
|
-
author_name: author_name,
|
170
|
-
author_email: author_email,
|
171
|
-
author_url: (author_url || "http://www.unknown.com"),
|
172
|
-
gem_url: (settings[:gem_url] || author_url),
|
173
|
-
company_name: (settings[:company_name] || author_name),
|
174
|
-
company_url: (settings[:company_url] || author_url),
|
175
|
-
github_user: (settings[:github_user] || Gemsmith::Kit.git_config_value("github.user") || "unknown"),
|
176
|
-
year: (settings[:year] || Time.now.year),
|
177
|
-
ruby_version: (settings[:ruby_version] || "2.0.0"),
|
178
|
-
rails_version: (settings[:rails_version] || "3.0"),
|
179
|
-
post_install_message: settings[:post_install_message],
|
180
|
-
bin: (options[:bin] || false),
|
181
|
-
rails: (options[:rails] || false),
|
182
|
-
pry: (options[:pry] || true),
|
183
|
-
guard: (options[:guard] || true),
|
184
|
-
rspec: (options[:rspec] || true),
|
185
|
-
travis: (options[:travis] || true),
|
186
|
-
code_climate: (options[:code_climate] || true)
|
187
|
-
}
|
188
|
-
end
|
189
90
|
end
|
190
91
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module Gemsmith
|
2
|
+
module CLIHelpers
|
3
|
+
# Answers the gem name (snake case).
|
4
|
+
# ==== Parameters
|
5
|
+
# * +name+ - Optional. The gem name. Default: nil
|
6
|
+
def gem_name name = nil
|
7
|
+
@gem_name ||= Thor::Util.snake_case name
|
8
|
+
end
|
9
|
+
|
10
|
+
# Answers the gem class (camel case).
|
11
|
+
# ==== Parameters
|
12
|
+
# * +name+ - Optional. The gem class. Default: nil
|
13
|
+
def gem_class name = nil
|
14
|
+
@gem_class ||= Thor::Util.camel_case name
|
15
|
+
end
|
16
|
+
|
17
|
+
# Answers all gem template options.
|
18
|
+
def template_options
|
19
|
+
@template_options
|
20
|
+
end
|
21
|
+
|
22
|
+
module_function
|
23
|
+
|
24
|
+
# Converts hash keys from strings to symbols (if any).
|
25
|
+
# ===== Parameters
|
26
|
+
# * +options+ - Optional. The hash to convert. Default: {}
|
27
|
+
def enforce_symbol_keys options = {}
|
28
|
+
options.each_with_object({}) { |(key, value), hash| hash[key.to_sym] = value }
|
29
|
+
end
|
30
|
+
|
31
|
+
# Prints currently installed gem name and version information.
|
32
|
+
# ===== Parameters
|
33
|
+
# * +gems+ - Required. The array of gem names (i.e. gem specifications).
|
34
|
+
def print_gems gems
|
35
|
+
say "Multiple versions found:"
|
36
|
+
gems.each_with_index do |spec, index|
|
37
|
+
say "#{index + 1}. #{spec.name} #{spec.version.version}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Picks a gem specification for processing.
|
42
|
+
# ===== Parameters
|
43
|
+
# * +gems+ - Required. The array of gem specifications.
|
44
|
+
# * +name+ - Required. The gem name to search for.
|
45
|
+
def pick_gem gems, name
|
46
|
+
result = ask "Please pick one (or type 'q' to quit):"
|
47
|
+
|
48
|
+
return if result == 'q' # Exit early.
|
49
|
+
|
50
|
+
if (1..gems.size).include?(result.to_i)
|
51
|
+
Gem::Specification.find_by_name name, gems[result.to_i - 1].version.version
|
52
|
+
else
|
53
|
+
error "Invalid option: #{result}"
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Opens selected gem within default editor.
|
59
|
+
# ===== Parameters
|
60
|
+
# * +spec+ - Required. The gem specification.
|
61
|
+
def open_gem spec
|
62
|
+
`$EDITOR #{spec.full_gem_path}` if spec
|
63
|
+
end
|
64
|
+
|
65
|
+
# Opens selected gem within default browser.
|
66
|
+
# ===== Parameters
|
67
|
+
# * +spec+ - Required. The gem specification.
|
68
|
+
def read_gem spec
|
69
|
+
`open #{spec.homepage}` if spec
|
70
|
+
end
|
71
|
+
|
72
|
+
# Processes a gem for given name and command.
|
73
|
+
# ===== Parameters
|
74
|
+
# * +name+ - Required. The gem name.
|
75
|
+
# * +command+ - Required. The command to process the gem.
|
76
|
+
def process_gem name, command
|
77
|
+
specs = Gem::Specification.find_all_by_name name
|
78
|
+
|
79
|
+
case
|
80
|
+
when specs.size == 1
|
81
|
+
send "#{command}_gem", specs.first
|
82
|
+
when specs.size > 1
|
83
|
+
print_gems specs
|
84
|
+
send "#{command}_gem", pick_gem(specs, name)
|
85
|
+
else
|
86
|
+
say "Unable to find gem: #{name}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|