Class: Application::FSBuilder
- Inherits:
-
Object
- Object
- Application::FSBuilder
- Defined in:
- lib/makegit/fs_builder.rb
Instance Attribute Summary collapse
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #bare ⇒ Object
- #build ⇒ Object
-
#initialize(project_name, template) ⇒ FSBuilder
constructor
A new instance of FSBuilder.
- #rubygem ⇒ Object
Constructor Details
#initialize(project_name, template) ⇒ FSBuilder
Returns a new instance of FSBuilder.
5 6 7 8 |
# File 'lib/makegit/fs_builder.rb', line 5 def initialize(project_name, template) @project_name = project_name @template = template || "bare" end |
Instance Attribute Details
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
3 4 5 |
# File 'lib/makegit/fs_builder.rb', line 3 def project_name @project_name end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
3 4 5 |
# File 'lib/makegit/fs_builder.rb', line 3 def template @template end |
Instance Method Details
#bare ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/makegit/fs_builder.rb', line 20 def STDOUT.puts "Building a bare project template" Dir.mkdir(project_name) Dir.chdir(project_name) do File.open("README.md", "w"){ |f| f.puts "\# #{project_name}"} end end |
#build ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/makegit/fs_builder.rb', line 10 def build if template == "bare" elsif template == "rubygem" rubygem else raise ArgumentError, "Could not find a template to build" end end |
#rubygem ⇒ Object
28 29 30 31 32 33 34 35 36 37 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 |
# File 'lib/makegit/fs_builder.rb', line 28 def rubygem STDOUT.puts "Building a RubyGem project template" Dir.mkdir(project_name) Dir.chdir(project_name) do File.open("#{project_name}.gemspec", "w"){ |f| f << "Gem::Specification.new do |s|\n" f << "\ts.name = \'\'\n" f << "\ts.version = \'\'\n" f << "\ts.date = \'\'\n" f << "\ts.summary = \'\'\n" f << "\ts.description = \'\'\n" f << "\ts.authors = \'[]\'\n" f << "\ts.email = \'\'\n" f << "\ts.files = \'[]\'\n" f << "\ts.executables << \'#{project_name}\'\n" f << "\ts.homepage = \'\'\n" f << "\ts.license = \'\'\n" f << "end" } File.open("Rakefile", "w") File.open("README.md", "w"){ |f| f.puts "\# #{project_name}: A RubyGem"} Dir.mkdir("bin") Dir.chdir("bin") do File.open(project_name, "w"){ |f| f.puts "\#!/usr/bin/env ruby"} end Dir.mkdir("lib") Dir.chdir("lib") do File.open("#{project_name}.rb", "w") end Dir.mkdir("test") Dir.chdir("test") do File.open("test_#{project_name}.rb", "w") end end end |