Class: RScaffold::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/rscaffold.rb

Constant Summary collapse

ATTRS =
%w(
  bin
  camel
  codeclimate
  description
  email
  fullname
  gemversion
  homepage
  license
  location
  owner
  remote
  remote_path
  req_rubyver
  summary
  travis
  usage
  whoami
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Project



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# 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 = '<%[email protected]_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

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



36
37
38
# File 'lib/rscaffold.rb', line 36

def name
  @name
end

Instance Method Details

#git_initObject



98
99
100
101
102
# File 'lib/rscaffold.rb', line 98

def git_init
  `git init`
  `git add .`
  `git commit -m'initial commit' -a`
end

#licenses_availObject



113
114
115
116
# 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) ⇒ Object



87
88
89
# File 'lib/rscaffold.rb', line 87

def rendered template
  ERB.new(contents(template), nil).result binding
end

#rvm_createObject



104
105
106
107
# File 'lib/rscaffold.rb', line 104

def rvm_create
  `rvm --create use #{cur_rubyver}@#{@name} --ruby-version`
  `bundle install`
end

#write(template) ⇒ Object



91
92
93
94
95
96
# 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_allObject



109
110
111
# File 'lib/rscaffold.rb', line 109

def write_all
  @location.keys.each{|template| self.write(template.to_s)}
end