class Straptible::Gem::Generators::Base

Attributes

name[RW]
opts[RW]

Public Class Methods

start() click to toggle source
Calls superclass method
# File lib/straptible/gem/generators/base.rb, line 12
def self.start
  tmpl_path = File.join('..', 'templates')
  source_root File.expand_path(tmpl_path, File.dirname(__FILE__))

  super
end

Public Instance Methods

author() click to toggle source
# File lib/straptible/gem/generators/base.rb, line 24
def author
  git_name.empty? ? 'TODO: Write your name' : git_name
end
commit_message() click to toggle source
# File lib/straptible/gem/generators/base.rb, line 53
def commit_message
  "Initial commit (Straptible #{Straptible::VERSION})"
end
constant_array() click to toggle source
# File lib/straptible/gem/generators/base.rb, line 49
def constant_array
  constant_name.split('::')
end
constant_name() click to toggle source
# File lib/straptible/gem/generators/base.rb, line 40
def constant_name
  cn = name.split('_').map(&:capitalize).join
  if cn =~ /-/
    cn.split('-').map { |q| q[0..0].upcase + q[1..-1] }.join('::')
  else
    cn
  end
end
email() click to toggle source
# File lib/straptible/gem/generators/base.rb, line 32
def email
  git_email.empty? ? 'TODO: Write your email address' : git_email
end
gem(name_or_path) click to toggle source
# File lib/straptible/gem/generators/base.rb, line 68
def gem(name_or_path)
  self.destination_root = File.expand_path(name_or_path, Dir.pwd)
  self.name = File.basename(name_or_path)

  self.opts = {
    name: name,
    namespaced_path: namespaced_path,
    constant_name: constant_name,
    constant_array: constant_array,
    author: author,
    email: email
  }

  template 'Gemfile.tt', opts
  template 'LICENSE.md.tt', opts
  template 'README.md.tt', opts
  template 'newgem.gemspec.tt', "#{name}.gemspec", opts
  template 'spec/spec_helper.rb.tt', 'spec/spec_helper.rb', opts

  template 'lib/newgem.rb.tt', "lib/#{namespaced_path}.rb", opts
  template 'lib/newgem/version.rb.tt',
           "lib/#{namespaced_path}/version.rb", opts

  copy_file 'Rakefile'
  copy_file 'gitignore', '.gitignore'
  copy_file 'rspec', '.rspec'
  copy_file 'travis.yml', '.travis.yml'

  git_init
end
git_email() click to toggle source
# File lib/straptible/gem/generators/base.rb, line 28
def git_email
  `git config user.email`.chomp
end
git_init() click to toggle source
# File lib/straptible/gem/generators/base.rb, line 57
def git_init
  inside destination_root do
    run 'git init .'
    run 'git add .'
    run "git commit -m '#{commit_message}'"
  end
end
git_name() click to toggle source
# File lib/straptible/gem/generators/base.rb, line 20
def git_name
  `git config user.name`.chomp
end
namespaced_path() click to toggle source
# File lib/straptible/gem/generators/base.rb, line 36
def namespaced_path
  name.tr('-', '/')
end