class RScaffold::Project

Constants

ATTRS

Attributes

name[R]

Public Class Methods

new(name) click to toggle source
# File lib/rscaffold.rb, line 38
def initialize name
  @name  = name
  @bin   = @name
  @camel = RScaffold.camel_case @name

  @cur_rubyver = '2.1'
  @erb_required_ruby_version = '<%=@spec.required_ruby_version.to_s%>'
  @req_rubyver = '>=1.8.7'
  @license = 'MIT'

  @today = Time.now.strftime '%Y-%m-%d'
  @year  = Time.now.year

  # This disgusting thing is to work across *nix, Windows, and Cygwin.
  @whoami   = ( ENV["USER"] || ENV["USERNAME"] ).sub(/.*\\/, '')
  @email    = `git config --get user.email`
  @fullname = `git config --get user.name`
  @owner    = @fullname

  @remote_path = "#{@whoami}/#{@name}"
  @remote      = "http://github.com/#{@remote_path}"
  @homepage    = @remote
  @travis      = travis_of      @remote_path
  @codeclimate = codeclimate_of @remote_path
  @gemversion  = gemversion_of  @name

  @summary     = "#FIXME summary"
  @description = "#FIXME description"
  @usage       = "#FIXME usage"
  @website     = "#FIXME website"

  @location = {
    :bin       => "bin/#{@bin}",
    :gemfile   => "Gemfile",
    :gemspec   => "#{@name}.gemspec",
    :gitignore => ".gitignore",
    :license   => "LICENSE",
    :man       => "man/man1/#{@bin}.1",
    :project   => "lib/#{@name}.rb",
    :rakefile  => "Rakefile",
    :readme    => "doc-src/README.md.erb",
    :rspec     => ".rspec",
    :spec      => "spec/#{@name}_spec.rb",
    :travis    => ".travis.yml",
    :version   => "lib/#{@name}/version.rb",
  }

end

Public Instance Methods

git_init() click to toggle source
# File lib/rscaffold.rb, line 98
def git_init
  `git init`
  `git add .`
  `git commit -m'initial commit' -a`
end
licenses_avail() click to toggle source
# File lib/rscaffold.rb, line 113
def licenses_avail
  l = Dir.entries(licenses).reject{|el| el =~ /^(\.|\.\.)$/}
  l.map{|fn| fn.sub(/\.erb$/, '')}
end
rendered(template) click to toggle source
# File lib/rscaffold.rb, line 87
def rendered template
  ERB.new(contents(template), nil).result binding
end
rvm_create() click to toggle source
# File lib/rscaffold.rb, line 104
def rvm_create
  `rvm --create use #{cur_rubyver}@#{@name} --ruby-version`
  `bundle install`
end
write(template) click to toggle source
# File lib/rscaffold.rb, line 91
def write template
  FileUtils.mkdir_p File.dirname @location[template.to_sym]
  File.open(@location[template.to_sym], 'w') do |file|
    file.write rendered template
  end
end
write_all() click to toggle source
# File lib/rscaffold.rb, line 109
def write_all
  @location.keys.each{|template| self.write(template.to_s)}
end

Private Instance Methods

codeclimate_of(path) click to toggle source
# File lib/rscaffold.rb, line 125
def codeclimate_of path
  codeclimate_dir = "https://codeclimate.com/github/#{path}"
  "[![Code Climate](#{codeclimate_dir}.png)](#{codeclimate_dir})"
end
contents(template) click to toggle source
# File lib/rscaffold.rb, line 135
def contents template
  if template == 'license'
    filename = @license
    dir = licenses
  else
    filename = template
    dir = templates
  end
  file     = "#{filename}.erb"
  File.read(File.join(dir, file))
end
gemversion_of(path) click to toggle source
# File lib/rscaffold.rb, line 130
def gemversion_of path
  gemversion_dir = "https://badge.fury.io/rb/#{path}"
  "[![Gem Version](#{gemversion_dir}.png)](#{gemversion_dir})"
end
licenses() click to toggle source
# File lib/rscaffold.rb, line 151
def licenses
  File.join(File.dirname(__FILE__), 'licenses')
end
templates() click to toggle source
# File lib/rscaffold.rb, line 147
def templates
  File.join(File.dirname(__FILE__), 'templates')
end
travis_of(path) click to toggle source
# File lib/rscaffold.rb, line 120
def travis_of path
  travis_dir = "https://travis-ci.org/#{path}"
  "[![Build Status](#{travis_dir}.png?branch=master)](#{travis_dir})"
end