gem_bootstrap 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rubocop.yml +9 -0
- data/CHANGELOGS.md +5 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +116 -0
- data/Rakefile +30 -0
- data/bin/gem_bootstrap +3 -0
- data/gem_bootstrap.gemspec +41 -0
- data/lib/gem_bootstrap/cli.rb +57 -0
- data/lib/gem_bootstrap/core_ext/hash/keys.rb +54 -0
- data/lib/gem_bootstrap/core_ext/object/blank.rb +105 -0
- data/lib/gem_bootstrap/gem_bootstrap.rb +35 -0
- data/lib/gem_bootstrap/git_utils.rb +49 -0
- data/lib/gem_bootstrap/misc_utils.rb +75 -0
- data/lib/gem_bootstrap/version.rb +3 -0
- data/lib/gem_bootstrap.rb +7 -0
- data/rubocop-todo.yml +36 -0
- data/templates/CHANGELOGS.md +5 -0
- data/templates/GNU_LICENSE +339 -0
- data/templates/Gemfile +4 -0
- data/templates/Guardfile +13 -0
- data/templates/MIT_LICENSE +22 -0
- data/templates/README.md +57 -0
- data/templates/Rakefile +29 -0
- data/templates/bin/newgem +4 -0
- data/templates/dot_gitignore +18 -0
- data/templates/dot_rubocop.yml +10 -0
- data/templates/dot_yardopts +2 -0
- data/templates/lib/newgem/cli.rb +33 -0
- data/templates/lib/newgem/core_ext/hash/keys.rb +54 -0
- data/templates/lib/newgem/logger.rb +10 -0
- data/templates/lib/newgem/newgem.rb +10 -0
- data/templates/lib/newgem/version.rb +3 -0
- data/templates/lib/newgem.rb +6 -0
- data/templates/newgem.gemspec.tt +30 -0
- data/templates/rubocop-todo.yml +92 -0
- data/templates/test/lib/newgem/test_newgem.rb +8 -0
- data/templates/test/test_helper.rb +8 -0
- data/test/lib/gem_bootstrap/test_gem_bootstrap.rb +9 -0
- data/test/test_helper.rb +8 -0
- metadata +273 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b971c9ff6eeff1e96a93856890d5e3b526893dae
|
4
|
+
data.tar.gz: 69a6c4147c0117e540b03b858345870bc5ec80f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 68276627da8235910abd8d04ef055d7810ef551aaf3332a99db3616165465d3bae1d8a89e8d1fff8bc9727a2cc67c624eac21cd0bac06298633832016cd0a2ef
|
7
|
+
data.tar.gz: 83ce45e72f24287cb641cd990eafc20863783e4a6c62bf3d23f17c91d187989708bce84ba30f4966348202620959c44a656b34224a542d67edd68baa8c8cc88a
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOGS.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Burin Choomnuan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
## gem_bootstrap
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/gem_bootstrap.svg)](http://badge.fury.io/rb/gem_bootstrap)
|
4
|
+
[![Dependency Status](https://gemnasium.com/agilecreativity/gem_bootstrap.png)](https://gemnasium.com/agilecreativity/gem_bootstrap)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/agilecreativity/gem_bootstrap.png)](https://codeclimate.com/github/agilecreativity/gem_bootstrap)
|
6
|
+
|
7
|
+
Generate the starting template for creating the ruby gem in ruby in one command.
|
8
|
+
|
9
|
+
### Features:
|
10
|
+
|
11
|
+
- Test framework using [Minitest][]
|
12
|
+
- Document with [Yard][]
|
13
|
+
- Style check with [Rubocop][]
|
14
|
+
- Debug with [Pry][]
|
15
|
+
- Initial git commit with [Grit] gem
|
16
|
+
- Build on top of the most popular [Thor][] framework
|
17
|
+
- Give you simple working structure that you can build upon but not dictate on
|
18
|
+
how you should do it
|
19
|
+
- Templates files are customizable to suite your specific need
|
20
|
+
|
21
|
+
### Requirements
|
22
|
+
|
23
|
+
#### Mandatory
|
24
|
+
|
25
|
+
- [Git][] the free and opensource distributed version control system.
|
26
|
+
|
27
|
+
### Optional
|
28
|
+
|
29
|
+
- Valid [Github][] account so that you can share your awesome gem with the community.
|
30
|
+
|
31
|
+
### Installation
|
32
|
+
|
33
|
+
Install the ruby gem
|
34
|
+
|
35
|
+
```sh
|
36
|
+
gem install gem_bootstrap
|
37
|
+
```
|
38
|
+
|
39
|
+
Then just run the `gem_bootstrap` without any argument for list of help
|
40
|
+
|
41
|
+
```
|
42
|
+
gem_bootstrap generate [GEM_NAME]
|
43
|
+
--github-id [GITHUB_ID]
|
44
|
+
--email [EMAIL]
|
45
|
+
--author [AUTHOR]
|
46
|
+
e.g.
|
47
|
+
gem_bootstrap generate awesome_gem
|
48
|
+
--github-id awesome_developer
|
49
|
+
--email cool@awesomedev.com
|
50
|
+
--author 'John Guru II'
|
51
|
+
gem_bootstrap help [COMMAND] # Describe available commands or one specific command
|
52
|
+
gem_bootstrap usage # Display help screen
|
53
|
+
```
|
54
|
+
To generate the gem just type the command like
|
55
|
+
|
56
|
+
```
|
57
|
+
gem_bootstrap generate awesome_gem --github-id awesome_developer -- email cool@awesomedev.com --author 'John Guru II'
|
58
|
+
```
|
59
|
+
Which should output something like
|
60
|
+
|
61
|
+
```
|
62
|
+
create awesome_gem/README.md
|
63
|
+
create awesome_gem/CHANGELOGS.md
|
64
|
+
create awesome_gem/.yardopts
|
65
|
+
create awesome_gem/.gitignore
|
66
|
+
create awesome_gem/Gemfile
|
67
|
+
create awesome_gem/Rakefile
|
68
|
+
create awesome_gem/Guardfile
|
69
|
+
create awesome_gem/.rubocop.yml
|
70
|
+
create awesome_gem/rubocop-todo.yml
|
71
|
+
create awesome_gem/awesome_gem.gemspec
|
72
|
+
create awesome_gem/bin/awesome_gem
|
73
|
+
create awesome_gem/lib/awesome_gem.rb
|
74
|
+
create awesome_gem/lib/awesome_gem/version.rb
|
75
|
+
create awesome_gem/lib/awesome_gem/logger.rb
|
76
|
+
create awesome_gem/lib/awesome_gem/cli.rb
|
77
|
+
create awesome_gem/lib/awesome_gem/awesome_gem.rb
|
78
|
+
create awesome_gem/lib/awesome_gem/core_ext/hash/keys.rb
|
79
|
+
create awesome_gem/test/test_helper.rb
|
80
|
+
create awesome_gem/test/lib/awesome_gem/test_awesome_gem.rb
|
81
|
+
create awesome_gem/LICENSE
|
82
|
+
```
|
83
|
+
|
84
|
+
```sh
|
85
|
+
# Change directory to the generated gem
|
86
|
+
cd awesome_gem
|
87
|
+
|
88
|
+
# Build the gem
|
89
|
+
bundle
|
90
|
+
|
91
|
+
# Run the default rake task (minitest and rubocop)
|
92
|
+
rake
|
93
|
+
|
94
|
+
# Install the gem to your local system
|
95
|
+
rake install
|
96
|
+
|
97
|
+
# You should have the basic command line that you can run like
|
98
|
+
awesome_gem
|
99
|
+
```
|
100
|
+
|
101
|
+
### Contributing
|
102
|
+
|
103
|
+
1. Fork it
|
104
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
105
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
106
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
107
|
+
5. Create new Pull Request
|
108
|
+
|
109
|
+
[Git]: http://git-scm.com/
|
110
|
+
[github]: https://github.com/
|
111
|
+
[Grit]: https://github.com/mojombo/grit
|
112
|
+
[Minitest]: https://github.com/seattlerb/minitest
|
113
|
+
[Thor]: https://github.com/erikhuda/thor
|
114
|
+
[Yard]: https://github.com/lsegal/yard
|
115
|
+
[Rubocop]: https://github.com/bbatsov/rubocop
|
116
|
+
[Pry]: https://github.com/pry/pry
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
project_name = 'gem_bootstrap'
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs << "lib/#{project_name}"
|
7
|
+
t.test_files = FileList["test/lib/#{project_name}/test_*.rb"]
|
8
|
+
t.verbose = true
|
9
|
+
end
|
10
|
+
|
11
|
+
task default: [:test, :rubocop]
|
12
|
+
|
13
|
+
task :pry do
|
14
|
+
require 'pry'
|
15
|
+
require 'awesome_print'
|
16
|
+
require_relative 'lib/gem_bootstrap'
|
17
|
+
include GemBootstrap
|
18
|
+
ARGV.clear
|
19
|
+
Pry.start
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rubocop/rake_task'
|
23
|
+
desc 'Run RuboCop on the lib directory'
|
24
|
+
Rubocop::RakeTask.new(:rubocop) do |task|
|
25
|
+
task.patterns = ['lib/**/*.rb']
|
26
|
+
# only show the files with failures
|
27
|
+
task.formatters = ['files']
|
28
|
+
# don't abort rake on failure
|
29
|
+
task.fail_on_error = false
|
30
|
+
end
|
data/bin/gem_bootstrap
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gem_bootstrap/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'gem_bootstrap'
|
8
|
+
spec.version = GemBootstrap::VERSION
|
9
|
+
spec.authors = ['Burin Choomnuan']
|
10
|
+
spec.email = ['agilecreativity@gmail.com']
|
11
|
+
spec.summary = %q(Bootstrap the creation of ruby gem so that you don't have to start from scratch)
|
12
|
+
spec.description = %q(Bootstrap the creation of ruby gem so that you don't have to start from scratch.
|
13
|
+
Build with simple, sensible default and very easy to extend)
|
14
|
+
spec.homepage = 'https://github.com/agilecreativity/gem_bootstrap'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
spec.files = Dir.glob('{bin,lib,templates}/**/*') + %w(Gemfile
|
17
|
+
Rakefile
|
18
|
+
gem_bootstrap.gemspec
|
19
|
+
README.md
|
20
|
+
CHANGELOGS.md
|
21
|
+
LICENSE
|
22
|
+
.rubocop.yml
|
23
|
+
.gitignore
|
24
|
+
rubocop-todo.yml)
|
25
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
26
|
+
spec.test_files = Dir.glob('test/**/*')
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
spec.add_runtime_dependency 'thor', '~> 0.19'
|
29
|
+
spec.add_runtime_dependency 'grit', '~> 2.5'
|
30
|
+
spec.add_development_dependency 'awesome_print', '~> 1.2'
|
31
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
32
|
+
spec.add_development_dependency 'gem-ctags', '~> 1.0'
|
33
|
+
spec.add_development_dependency 'minitest', '~> 5.3'
|
34
|
+
spec.add_development_dependency 'minitest-spec-context', '~> 0.0.3'
|
35
|
+
spec.add_development_dependency 'guard', '~> 2.6'
|
36
|
+
spec.add_development_dependency 'guard-minitest', '~> 2.2'
|
37
|
+
spec.add_development_dependency 'pry', '~> 0.9'
|
38
|
+
spec.add_development_dependency 'rake', '~> 10.3'
|
39
|
+
spec.add_development_dependency 'rubocop', '~> 0.21'
|
40
|
+
spec.add_development_dependency 'yard', '~> 0.8.7'
|
41
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require_relative './misc_utils'
|
3
|
+
require_relative './git_utils'
|
4
|
+
module GemBootstrap
|
5
|
+
class CLI < Thor::Group
|
6
|
+
include Thor::Actions
|
7
|
+
argument :name
|
8
|
+
class_option :github_id,
|
9
|
+
aliases: '-g',
|
10
|
+
desc: 'github profile id',
|
11
|
+
required: true
|
12
|
+
class_option :author,
|
13
|
+
aliases: '-a',
|
14
|
+
desc: 'Full name of the author',
|
15
|
+
required: true
|
16
|
+
class_option :email,
|
17
|
+
aliases: '-e',
|
18
|
+
desc: 'Email for github',
|
19
|
+
required: true
|
20
|
+
def self.source_root
|
21
|
+
File.dirname(__FILE__)
|
22
|
+
end
|
23
|
+
|
24
|
+
# rubocop:disable MethodLength, LineLength
|
25
|
+
def create_lib_file
|
26
|
+
template '../../templates/README.md', "#{name}/README.md"
|
27
|
+
template '../../templates/CHANGELOGS.md', "#{name}/CHANGELOGS.md"
|
28
|
+
template '../../templates/dot_yardopts', "#{name}/.yardopts"
|
29
|
+
template '../../templates/dot_gitignore', "#{name}/.gitignore"
|
30
|
+
template '../../templates/Gemfile', "#{name}/Gemfile"
|
31
|
+
template '../../templates/Rakefile', "#{name}/Rakefile"
|
32
|
+
template '../../templates/Guardfile', "#{name}/Guardfile"
|
33
|
+
template '../../templates/dot_rubocop.yml', "#{name}/.rubocop.yml"
|
34
|
+
template '../../templates/rubocop-todo.yml', "#{name}/rubocop-todo.yml"
|
35
|
+
template '../../templates/newgem.gemspec.tt', "#{name}/#{name}.gemspec"
|
36
|
+
template '../../templates/bin/newgem', "#{name}/bin/#{name}"
|
37
|
+
template '../../templates/lib/newgem.rb', "#{name}/lib/#{name}.rb"
|
38
|
+
template '../../templates/lib/newgem/version.rb', "#{name}/lib/#{name}/version.rb"
|
39
|
+
template '../../templates/lib/newgem/logger.rb', "#{name}/lib/#{name}/logger.rb"
|
40
|
+
template '../../templates/lib/newgem/cli.rb', "#{name}/lib/#{name}/cli.rb"
|
41
|
+
template '../../templates/lib/newgem/newgem.rb', "#{name}/lib/#{name}/#{name}.rb"
|
42
|
+
template '../../templates/lib/newgem/core_ext/hash/keys.rb', "#{name}/lib/#{name}/core_ext/hash/keys.rb"
|
43
|
+
template '../../templates/test/test_helper.rb', "#{name}/test/test_helper.rb"
|
44
|
+
template '../../templates/test/lib/newgem/test_newgem.rb', "#{name}/test/lib/#{name}/test_#{name}.rb"
|
45
|
+
end
|
46
|
+
# rubocop:enable all
|
47
|
+
|
48
|
+
def copy_licence
|
49
|
+
copy_file '../../templates/MIT_LICENSE', "#{name}/LICENSE"
|
50
|
+
end
|
51
|
+
|
52
|
+
# Create the git project to store our generated code
|
53
|
+
def create_git_project
|
54
|
+
GemBootstrap::GitUtils.create_git_project(File.expand_path(name), name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Hash
|
2
|
+
# from: activesupport/lib/active_support/core_ext/hash/keys.rb
|
3
|
+
#
|
4
|
+
# hash = { name: 'Rob', age: '28' }
|
5
|
+
# hash.transform_keys{ |key| key.to_s.upcase }
|
6
|
+
# => { "NAME" => "Rob", "AGE" => "28" }
|
7
|
+
def transform_keys
|
8
|
+
result = {}
|
9
|
+
each_key do |key|
|
10
|
+
result[yield(key)] = self[key]
|
11
|
+
end
|
12
|
+
result
|
13
|
+
end
|
14
|
+
|
15
|
+
def transform_keys!(&block)
|
16
|
+
keys.each do |key|
|
17
|
+
value = delete(key)
|
18
|
+
self[yield(key)] = value.is_a?(Hash) ? value.transform_keys!(&block) : value
|
19
|
+
end
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
# hash = { 'name' => 'Rob', 'age' => '28' }
|
24
|
+
# hash.symbolize_keys
|
25
|
+
# => { name: "Rob", age: "28" }
|
26
|
+
def symbolize_keys
|
27
|
+
transform_keys { |key| key.to_sym rescue key }
|
28
|
+
end
|
29
|
+
|
30
|
+
# from: activesupport/lib/active_support/core_ext/hash/keys.rb, line 135
|
31
|
+
def symbolize_keys!
|
32
|
+
transform_keys! { |key| key.to_sym rescue key }
|
33
|
+
end
|
34
|
+
|
35
|
+
# Merges the caller into +other_hash+. For example,
|
36
|
+
#
|
37
|
+
# options = options.reverse_merge(size: 25, velocity: 10)
|
38
|
+
#
|
39
|
+
# is equivalent to
|
40
|
+
#
|
41
|
+
# options = { size: 25, velocity: 10 }.merge(options)
|
42
|
+
#
|
43
|
+
# This is particularly useful for initializing an options hash
|
44
|
+
# with default values.
|
45
|
+
def reverse_merge(other_hash)
|
46
|
+
other_hash.merge(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Destructive +reverse_merge+.
|
50
|
+
def reverse_merge!(other_hash)
|
51
|
+
# right wins if there is no left
|
52
|
+
merge!(other_hash) { |_key, left, _right| left }
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# from: active_support/core_ext/object/blank.rb
|
3
|
+
class Object
|
4
|
+
# An object is blank if it's false, empty, or a whitespace string.
|
5
|
+
# For example, '', ' ', +nil+, [], and {} are all blank.
|
6
|
+
#
|
7
|
+
# This simplifies:
|
8
|
+
#
|
9
|
+
# if address.nil? || address.empty?
|
10
|
+
#
|
11
|
+
# ...to:
|
12
|
+
#
|
13
|
+
# if address.blank?
|
14
|
+
def blank?
|
15
|
+
respond_to?(:empty?) ? empty? : !self
|
16
|
+
end
|
17
|
+
|
18
|
+
# An object is present if it's not <tt>blank?</tt>.
|
19
|
+
def present?
|
20
|
+
!blank?
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns object if it's <tt>present?</tt> otherwise returns +nil+.
|
24
|
+
# <tt>object.presence</tt> is equivalent to <tt>object.present? ? object : nil</tt>.
|
25
|
+
#
|
26
|
+
# This is handy for any representation of objects where blank is the same
|
27
|
+
# as not present at all. For example, this simplifies a common check for
|
28
|
+
# HTTP POST/query parameters:
|
29
|
+
#
|
30
|
+
# state = params[:state] if params[:state].present?
|
31
|
+
# country = params[:country] if params[:country].present?
|
32
|
+
# region = state || country || 'US'
|
33
|
+
#
|
34
|
+
# ...becomes:
|
35
|
+
#
|
36
|
+
# region = params[:state].presence || params[:country].presence || 'US'
|
37
|
+
def presence
|
38
|
+
self if present?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class NilClass
|
43
|
+
# +nil+ is blank:
|
44
|
+
#
|
45
|
+
# nil.blank? # => true
|
46
|
+
def blank?
|
47
|
+
true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class FalseClass
|
52
|
+
# +false+ is blank:
|
53
|
+
#
|
54
|
+
# false.blank? # => true
|
55
|
+
def blank?
|
56
|
+
true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class TrueClass
|
61
|
+
# +true+ is not blank:
|
62
|
+
#
|
63
|
+
# true.blank? # => false
|
64
|
+
def blank?
|
65
|
+
false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Array
|
70
|
+
# An array is blank if it's empty:
|
71
|
+
#
|
72
|
+
# [].blank? # => true
|
73
|
+
# [1,2,3].blank? # => false
|
74
|
+
alias_method :blank?, :empty?
|
75
|
+
end
|
76
|
+
|
77
|
+
class Hash
|
78
|
+
# A hash is blank if it's empty:
|
79
|
+
#
|
80
|
+
# {}.blank? # => true
|
81
|
+
# { key: 'value' }.blank? # => false
|
82
|
+
alias_method :blank?, :empty?
|
83
|
+
end
|
84
|
+
|
85
|
+
class String
|
86
|
+
# A string is blank if it's empty or contains whitespaces only:
|
87
|
+
#
|
88
|
+
# ''.blank? # => true
|
89
|
+
# ' '.blank? # => true
|
90
|
+
# ' '.blank? # => true
|
91
|
+
# ' something here '.blank? # => false
|
92
|
+
def blank?
|
93
|
+
self !~ /[^[:space:]]/
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class Numeric #:nodoc:
|
98
|
+
# No number is blank:
|
99
|
+
#
|
100
|
+
# 1.blank? # => false
|
101
|
+
# 0.blank? # => false
|
102
|
+
def blank?
|
103
|
+
false
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require_relative './cli'
|
3
|
+
module GemBootstrap
|
4
|
+
class MainCLI < Thor
|
5
|
+
register GemBootstrap::CLI,
|
6
|
+
'generate',
|
7
|
+
'generate',
|
8
|
+
'Generate the starting template for CLI'
|
9
|
+
|
10
|
+
desc 'usage', 'Display help screen'
|
11
|
+
def usage
|
12
|
+
generate_usage = <<-EOT
|
13
|
+
gem_bootstrap generate [GEM_NAME]
|
14
|
+
--github-id [GITHUB_ID]
|
15
|
+
--email [EMAIL]
|
16
|
+
--author [AUTHOR]
|
17
|
+
e.g. create a gem name 'awesome_gem'
|
18
|
+
gem_bootstrap generate awesome_gem
|
19
|
+
--github-id awesome_developer
|
20
|
+
--email cool@awesomedev.com
|
21
|
+
--author 'John Guru II'
|
22
|
+
EOT
|
23
|
+
|
24
|
+
help_text = <<-EOT
|
25
|
+
gem_bootstrap help [COMMAND] # Describe available commands or one specific command
|
26
|
+
gem_bootstrap usage # Display help screen
|
27
|
+
EOT
|
28
|
+
|
29
|
+
puts generate_usage
|
30
|
+
puts help_text.gsub(/^\s+/, '')
|
31
|
+
end
|
32
|
+
|
33
|
+
default_task :usage
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'grit'
|
2
|
+
module GemBootstrap
|
3
|
+
class GitUtils
|
4
|
+
class << self
|
5
|
+
# create new git repo from a given directory
|
6
|
+
#
|
7
|
+
# @param [String] base_dir the starting directory
|
8
|
+
# @param [String] gem_name the name of the gem we are creating
|
9
|
+
def create_git_project(base_dir, gem_name)
|
10
|
+
base_dir = File.expand_path(base_dir) # so that it works with ~/codes/etc
|
11
|
+
files = MiscUtils.files base_dir: base_dir,
|
12
|
+
non_exts: %w(Gemfile
|
13
|
+
Rakefile
|
14
|
+
Guardfile
|
15
|
+
LICENSE
|
16
|
+
.rubocop.yml
|
17
|
+
.yardopts
|
18
|
+
.gitignore) << gem_name,
|
19
|
+
exts: %w(md rb gemspec yml),
|
20
|
+
recursive: true
|
21
|
+
git_init(base_dir: base_dir)
|
22
|
+
git_add(files, base_dir: base_dir, gem_name: gem_name)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Run the git init on a given directory
|
26
|
+
#
|
27
|
+
# @param [String] base_dir the base directory
|
28
|
+
def git_init(options = {})
|
29
|
+
current_dir = File.expand_path(options[:base_dir])
|
30
|
+
base_dir = options[:base_dir] || Dir.pwd
|
31
|
+
Dir.chdir(base_dir)
|
32
|
+
MiscUtils.shell(%w(git init) << base_dir)
|
33
|
+
Dir.chdir(current_dir)
|
34
|
+
end
|
35
|
+
|
36
|
+
def git_add(files, options = {})
|
37
|
+
base_dir = File.expand_path(options[:base_dir])
|
38
|
+
Dir.chdir(base_dir) do
|
39
|
+
git = Grit::Repo.new(File.expand_path('.'))
|
40
|
+
files.each do |file|
|
41
|
+
# puts "Add '#{file}' to repository"
|
42
|
+
git.add(file)
|
43
|
+
end
|
44
|
+
git.commit_index('Initial commit')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'open3'
|
2
|
+
module GemBootstrap
|
3
|
+
class MiscUtils
|
4
|
+
|
5
|
+
CustomError = Class.new(StandardError)
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# Receives a string and convert it to snake case.
|
9
|
+
# SnakeCase returns snake_case.
|
10
|
+
#
|
11
|
+
# @param [String] str the input string
|
12
|
+
def snake_case(str)
|
13
|
+
return str.downcase if str =~ /^[A-Z_]+$/
|
14
|
+
str.gsub(/\B[A-Z]/, '_\&').squeeze('_') =~ /_*(.*)/
|
15
|
+
$+.downcase
|
16
|
+
end
|
17
|
+
|
18
|
+
# Receives a string and convert it to camel case.
|
19
|
+
# camel_case returns CamelCase.
|
20
|
+
#
|
21
|
+
# @param [String] str the input string
|
22
|
+
def camel_case(str)
|
23
|
+
return str if str !~ /_/ && str =~ /[A-Z]+.*/
|
24
|
+
str.split('_').map { |i| i.capitalize }.join
|
25
|
+
end
|
26
|
+
|
27
|
+
# List files base on some extension
|
28
|
+
def files(args = {})
|
29
|
+
opts = {
|
30
|
+
base_dir: Dir.pwd,
|
31
|
+
recursive: false,
|
32
|
+
exts: [],
|
33
|
+
non_exts: []
|
34
|
+
}.merge(args)
|
35
|
+
|
36
|
+
base_dir = opts[:base_dir]
|
37
|
+
fail CustomError, "The directory #{base_dir} is not valid or or not readable!" unless File.exist?(base_dir)
|
38
|
+
|
39
|
+
wildcard = opts[:recursive] ? '**' : ''
|
40
|
+
exts = opts[:exts]
|
41
|
+
non_exts = opts[:non_exts]
|
42
|
+
|
43
|
+
file_with_extension = Dir.glob(File.join(base_dir, wildcard, "*.{#{exts.join(',')}}"))
|
44
|
+
file_with_no_extension = no_extension_files(base_dir, wildcard, non_exts)
|
45
|
+
|
46
|
+
(file_with_extension + file_with_no_extension).sort
|
47
|
+
end
|
48
|
+
|
49
|
+
# List files that do not have the extension
|
50
|
+
#
|
51
|
+
# @return list of files that does not have any extension
|
52
|
+
def no_extension_files(base_dir, wildcard, non_exts = [])
|
53
|
+
list = []
|
54
|
+
unless non_exts.empty?
|
55
|
+
list = Dir.glob(File.join(base_dir, wildcard, "{#{non_exts.join(',')}}"))
|
56
|
+
end
|
57
|
+
list
|
58
|
+
end
|
59
|
+
|
60
|
+
# Wrapper function to call the 'popen3' and return the result
|
61
|
+
#
|
62
|
+
# @param [Array<String>] commands list of command
|
63
|
+
# @return [String] result of the command as the string
|
64
|
+
def shell(commands = [])
|
65
|
+
begin
|
66
|
+
command = commands.join(' ')
|
67
|
+
stdin, _stderr, _status = Open3.capture3(command)
|
68
|
+
rescue Exception => e
|
69
|
+
raise "Problem processing #{command}, #{e.message}"
|
70
|
+
end
|
71
|
+
stdin
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require_relative './gem_bootstrap/version'
|
2
|
+
require_relative './gem_bootstrap/cli'
|
3
|
+
require_relative './gem_bootstrap/git_utils'
|
4
|
+
require_relative './gem_bootstrap/misc_utils'
|
5
|
+
require_relative './gem_bootstrap/gem_bootstrap'
|
6
|
+
require_relative './gem_bootstrap/core_ext/object/blank'
|
7
|
+
include GemBootstrap
|