gemmy_rb 0.0.1a

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f6e3186aa7bdf083d7900fb09e70eb9f8c6d580d
4
+ data.tar.gz: 567648eade0d418f02344b1ad88fdda5ed4f9c51
5
+ SHA512:
6
+ metadata.gz: d005a8beab2961a98672f26a78e7253138f5b2e53e7e0416fde195f6120ec894babbe69a056ea98b29f82929879d40d44f6419915fc980e4d8ac9fea7283b9ad
7
+ data.tar.gz: fdd195ff2a642cf028607084ecd3721cb2e4211ac5f4c1e8cd6041ecc7a47a90cf64b6d4daeba7ad98310d72516e8628cfb1cde855ed3828120f5245d4065233
@@ -0,0 +1,3 @@
1
+ #! /usr/bin/env ruby
2
+ require 'gemmy/cli'
3
+ Gemmy::CLI.start
@@ -0,0 +1,18 @@
1
+ require 'gemmy/config'
2
+ require 'gemmy/runner'
3
+ require 'gemmy/plugin'
4
+
5
+ module Gemmy
6
+ class << self
7
+ def root_dir
8
+ File.expand_path('../..', __FILE__)
9
+ end
10
+
11
+ def bootstrap(opts = {})
12
+ config = opts[:config] || Gemmy::Config.default
13
+ plugins = opts[:plugins] || Gemmy::Plugin.defaults(config)
14
+ runner = Gemmy::Runner.new(config, plugins)
15
+ runner.run
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,58 @@
1
+ require 'thor'
2
+ require 'gemmy'
3
+
4
+ module Gemmy
5
+ class CLI < Thor
6
+ desc 'init', 'Initialize gem'
7
+ option :dir, type: :string
8
+ option :authors, type: :string
9
+ option :email, type: :string
10
+ option :name, type: :string
11
+ option :homepage, type: :string
12
+ option :summary, type: :string
13
+ option :description, type: :string
14
+ def init
15
+ opts = options.dup
16
+ if opts[:dir]
17
+ opts[:dir] = File.join(Dir.getwd, opts[:dir])
18
+ else
19
+ opts[:dir] = Dir.getwd
20
+ end
21
+
22
+ if opts[:authors]
23
+ opts[:authors] = opts[:authors].split(',')
24
+ else
25
+ opts[:authors] = [`git config user.name`.strip]
26
+ end
27
+
28
+ opts[:email] ||= `git config user.email`.strip
29
+ opts[:name] ||= opts[:dir].split(File::SEPARATOR).last
30
+ opts[:homepage] ||= "https://github.com/#{`git config github.user`.strip}/#{opts[:name]}"
31
+ opts[:summary] ||= prompt_for('Summary')
32
+ opts[:description] ||= prompt_for('Description')
33
+
34
+ puts "Initializing gem '#{opts[:name]}' in #{opts[:dir]}"
35
+ puts opts.map {|k,v| "#{k.to_s.capitalize}: #{v}"}
36
+ .map {|s| s.prepend '* '}
37
+ .join("\n")
38
+
39
+ config = Gemmy::Config.default.merge({
40
+ gem_name: opts[:name],
41
+ gem_authors: [opts[:authors]],
42
+ gem_email: opts[:email],
43
+ gem_homepage: opts[:homepage],
44
+ gem_summary: opts[:summary],
45
+ gem_description: opts[:description],
46
+ dir: opts[:dir]
47
+ })
48
+ Gemmy.bootstrap(config: config)
49
+ end
50
+
51
+ private
52
+
53
+ def prompt_for(str)
54
+ print str + ': '
55
+ $stdin.gets.strip
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,67 @@
1
+ require 'erb'
2
+
3
+ module Gemmy
4
+ class Config
5
+ class << self
6
+ def default
7
+ new({
8
+ dir: Dir.getwd,
9
+ template_dir: File.join(Gemmy.root_dir, 'templates'),
10
+ test_style: :spec,
11
+ test_library: :minitest,
12
+ gem_name: nil,
13
+ gem_summary: '',
14
+ gem_description: '',
15
+ gem_licenses: ['MIT'],
16
+ gem_initial_version: '0.0.0'
17
+ })
18
+ end
19
+
20
+ def load_file(yml_file)
21
+ new(YAML.load_file(yml_file))
22
+ end
23
+ end
24
+
25
+ def initialize(config = {})
26
+ @config = config
27
+ end
28
+
29
+ def merge(hash)
30
+ tap { @config = @config.merge(hash) }
31
+ end
32
+
33
+ def validate
34
+ [:gem_name, :dir].each do |sym|
35
+ raise ArgumentError.new("#{sym} required") if !respond_to?(sym) || public_send(sym).nil?
36
+ end
37
+ end
38
+
39
+ def apply_to_template(template)
40
+ ERB.new(template).result(binding)
41
+ end
42
+
43
+ def respond_to_missing?(sym, include_private = false)
44
+ @config.has_key? sym
45
+ end
46
+
47
+ def gem_module_name
48
+ gem_name.split('_').map {|s| capitalize s}.join
49
+ .split('-').map {|s| capitalize s}.join('::')
50
+ end
51
+
52
+ def gem_base_path
53
+ gem_name.gsub('-', '/')
54
+ end
55
+
56
+ def method_missing(sym, *args)
57
+ return @config[sym] if @config.has_key? sym
58
+ super
59
+ end
60
+
61
+ private
62
+
63
+ def capitalize(s)
64
+ s[0].upcase << s[1..-1]
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,49 @@
1
+ require 'gemmy/plugin/template_generator'
2
+ require 'gemmy/plugin/test_directory_generator'
3
+ require 'gemmy/plugin/gemspec_generator'
4
+
5
+ module Gemmy
6
+ class Plugin
7
+ # Plugins are duck typed on #run
8
+ def run; end
9
+
10
+ class << self
11
+ def defaults(config)
12
+ [
13
+ Gemmy::Plugin::TemplateGenerator.new(
14
+ config: config,
15
+ template: File.join(config.template_dir, 'Gemfile.erb'),
16
+ out: File.join(config.dir, 'Gemfile')
17
+ ),
18
+ Gemmy::Plugin::TemplateGenerator.new(
19
+ config: config,
20
+ template: File.join(config.template_dir, 'Rakefile.erb'),
21
+ out: File.join(config.dir, 'Rakefile')
22
+ ),
23
+ Gemmy::Plugin::TemplateGenerator.new(
24
+ config: config,
25
+ template: File.join(config.template_dir, 'README.md.erb'),
26
+ out: File.join(config.dir, 'README.md')
27
+ ),
28
+ Gemmy::Plugin::TemplateGenerator.new(
29
+ config: config,
30
+ template: File.join(config.template_dir, 'gitignore'),
31
+ out: File.join(config.dir, '.gitignore')
32
+ ),
33
+ Gemmy::Plugin::TestDirectoryGenerator.new(
34
+ config: config,
35
+ helper_template: File.join(config.template_dir, 'test_helper.rb.erb'),
36
+ test_style: config.test_style,
37
+ working_dir: config.dir
38
+ ),
39
+ Gemmy::Plugin::GemspecGenerator.new(
40
+ config: config,
41
+ gemspec_template: File.join(config.template_dir, 'gemspec.erb'),
42
+ version_template: File.join(config.template_dir, 'version.rb.erb'),
43
+ base_module_template: File.join(config.template_dir, 'base_module.rb.erb')
44
+ )
45
+ ]
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ require 'gemmy/template_writer'
2
+
3
+ module Gemmy
4
+ class Plugin
5
+ class GemspecGenerator
6
+ def initialize(config: nil, gemspec_template: nil, version_template: nil, base_module_template: nil)
7
+ @writers = [
8
+ Gemmy::TemplateWriter.new(
9
+ config,
10
+ gemspec_template,
11
+ File.join(config.dir, "#{config.gem_name}.gemspec")
12
+ ),
13
+ Gemmy::TemplateWriter.new(
14
+ config,
15
+ version_template,
16
+ File.join(config.dir, 'lib', config.gem_base_path, 'version.rb')
17
+ ),
18
+ Gemmy::TemplateWriter.new(
19
+ config,
20
+ base_module_template,
21
+ File.join(config.dir, 'lib', config.gem_base_path + '.rb')
22
+ )
23
+ ]
24
+ end
25
+
26
+ def run
27
+ @writers.each(&:write)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ require 'gemmy/template_writer'
2
+
3
+ module Gemmy
4
+ class Plugin
5
+ class TemplateGenerator
6
+ def initialize(config: nil, template: nil, out: nil)
7
+ @writer = Gemmy::TemplateWriter.new(config, template, out)
8
+ end
9
+
10
+ def run
11
+ @writer.write
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'gemmy/template_writer'
2
+
3
+ module Gemmy
4
+ class Plugin
5
+ class TestDirectoryGenerator
6
+ def initialize(config: nil, helper_template: nil, test_style: nil, working_dir: nil)
7
+ @writer = Gemmy::TemplateWriter.new(
8
+ config,
9
+ helper_template,
10
+ File.join(working_dir, test_style.to_s, "#{test_style}_helper.rb")
11
+ )
12
+ end
13
+
14
+ def run
15
+ @writer.write
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module Gemmy
2
+ class Runner
3
+ def initialize(config, plugins)
4
+ @config = config
5
+ @plugins = plugins
6
+ end
7
+
8
+ def run
9
+ @config.validate
10
+ Dir.mkdir(@config.dir) unless Dir.exists?(@config.dir)
11
+ @plugins.each { |p| p.run }
12
+ end
13
+ end
14
+ end
15
+
@@ -0,0 +1,24 @@
1
+ require 'fileutils'
2
+
3
+ module Gemmy
4
+ class TemplateWriter
5
+ def initialize(config, template_path, out)
6
+ @config = config
7
+ @template_path = template_path
8
+ @out = out
9
+ end
10
+
11
+ def write
12
+ FileUtils.mkdir_p(File.dirname(@out))
13
+ File.open(@out, 'w') do |f|
14
+ is_erb = !!@template_path[/\.erb$/]
15
+ template = File.read(@template_path)
16
+ if is_erb
17
+ f.write @config.apply_to_template(template)
18
+ else
19
+ f.write template
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Gemmy
2
+ VERSION = '0.0.1a'
3
+ end
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,7 @@
1
+ # <%= gem_name %>
2
+ <% if gem_summary.length > 0 %>
3
+ <%= gem_summary %>
4
+ <% end %><% if gem_description.length > 0 %>
5
+ ## Description
6
+
7
+ <%= gem_description %><% end %>
@@ -0,0 +1,62 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.name = :<%= test_style %>
5
+ t.libs << '<%= test_style %>'
6
+ t.test_files = FileList['<%= test_style %>/**/*<%= test_style %>.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => [:<%= test_style %>]
11
+
12
+ desc 'rm all *.gem files'
13
+ task :clean do
14
+ require 'fileutils'
15
+ FileUtils.rm Dir.glob('*.gem')
16
+ end
17
+
18
+ desc 'build gem'
19
+ task :build do
20
+ gemspec = Dir.glob('*.gemspec').first
21
+ system "gem build #{gemspec}"
22
+ end
23
+
24
+ desc 'install local gem'
25
+ task :install_local do
26
+ gem = Dir.glob('*.gem').first
27
+ system "gem install #{gem} --local"
28
+ end
29
+
30
+ desc 'build gem and push it to rubygems'
31
+ task :deploy => [:clean, :build] do
32
+ gem = Dir.glob('*.gem').first
33
+ system "gem push #{gem}"
34
+ end
35
+
36
+ desc 'runs through entire deploy process'
37
+ task :full_deploy => [:<%= test_style %>, :change_version] do
38
+ system "git push && git push --tags"
39
+ Rake::Task['deploy'].invoke
40
+ end
41
+
42
+ task :change_version do
43
+ raise "Version required: ENV['TO']" unless ENV['TO']
44
+
45
+ puts 'Checking for existing tag'
46
+ raise "Tag '#{ENV['TO']}' already exists!" unless `git tag -l $TO`.empty?
47
+
48
+ puts "Updating version.rb to '#{ENV['TO']}'"
49
+ version_file = '<%= File.join('lib', gem_base_path, 'version.rb') %>'
50
+ before_text = File.read(version_file)
51
+ text = before_text.gsub(/(?<=').+(?=')/, ENV['TO'])
52
+ raise "Aborting: Version didn't change" if text == before_text
53
+ File.open(version_file, 'w') {|f| f.puts text}
54
+
55
+ puts 'Committing version.rb'
56
+ exit(1) unless system "git add <%= File.join('lib', gem_base_path, 'version.rb') %>"
57
+ exit(1) unless system "git commit -m 'bump to version #{ENV['TO']}'"
58
+ exit(1) unless system "git tag #{ENV['TO']}"
59
+
60
+ puts "Tag '#{ENV['TO']}' generated. Don't forget to push --tags! :)"
61
+ end
62
+
@@ -0,0 +1 @@
1
+ require '<%= File.join(gem_base_path, 'version') %>'
@@ -0,0 +1,18 @@
1
+ require_relative '<%= File.join('lib', gem_base_path, 'version') %>'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = '<%= gem_name %>'
5
+ s.version = <%= gem_module_name %>::VERSION
6
+ s.licenses = [<%= gem_licenses.map {|l| "'#{l}'"}.join(', ') %>]
7
+ s.summary = '<%= gem_summary %>'
8
+ s.description = '<%= gem_description %>'
9
+ s.authors = [<%= gem_authors.map {|a| "'#{a}'"}.join(', ') %>]
10
+ s.email = '<%= gem_email %>'
11
+ s.files = Dir['lib/**/*.rb']
12
+ s.homepage = '<%= gem_homepage %>'
13
+ <%
14
+ # TODO: if plugins.include? Rakefile
15
+ %>
16
+ s.add_development_dependency 'rake', '~>0'
17
+ end
18
+
@@ -0,0 +1,4 @@
1
+ .ruby-version
2
+ Gemfile.lock
3
+ *.gem
4
+ coverage
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.push 'lib', __FILE__
2
+ require '<%= gem_base_path %>'
3
+ <% if test_library == :minitest %>require 'minitest/autorun'
4
+ <% if test_style == :spec %>require 'minitest/spec'<% end %><% end %>
@@ -0,0 +1,19 @@
1
+ <%=
2
+ space_factor = 2
3
+ nesting = -1
4
+ ''.tap do |out|
5
+ gem_module_name.split('::').each do |mod_part|
6
+ nesting += 1
7
+ out << ' ' * nesting * space_factor << 'module ' << mod_part << "\n"
8
+ end
9
+ end
10
+ %><%= ' ' * (nesting + 1) * space_factor %>VERSION = '<%= gem_initial_version %>'
11
+ <%=
12
+ ''.tap do |out|
13
+ while nesting >= 0
14
+ out << ' ' * nesting * space_factor << "end"
15
+ out << "\n" unless nesting == 0
16
+ nesting -= 1
17
+ end
18
+ end
19
+ %>
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemmy_rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1a
5
+ platform: ruby
6
+ authors:
7
+ - jbodah
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Create a lot of gems? Try gemmy_rb!
14
+ email: jb3689@yahoo.com
15
+ executables:
16
+ - gemmy
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/gemmy
21
+ - lib/gemmy.rb
22
+ - lib/gemmy/cli.rb
23
+ - lib/gemmy/config.rb
24
+ - lib/gemmy/plugin.rb
25
+ - lib/gemmy/plugin/gemspec_generator.rb
26
+ - lib/gemmy/plugin/template_generator.rb
27
+ - lib/gemmy/plugin/test_directory_generator.rb
28
+ - lib/gemmy/runner.rb
29
+ - lib/gemmy/template_writer.rb
30
+ - lib/gemmy/version.rb
31
+ - templates/Gemfile.erb
32
+ - templates/README.md.erb
33
+ - templates/Rakefile.erb
34
+ - templates/base_module.rb.erb
35
+ - templates/gemspec.erb
36
+ - templates/gitignore
37
+ - templates/test_helper.rb.erb
38
+ - templates/version.rb.erb
39
+ homepage: https://github.com/jbodah/gemmy_rb
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">"
55
+ - !ruby/object:Gem::Version
56
+ version: 1.3.1
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.2.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: a gem for generating other gems
63
+ test_files: []