Class: HotPotato::GenerateAppTask
- Inherits:
-
Object
- Object
- HotPotato::GenerateAppTask
- Defined in:
- lib/hot_potato/generate_app_task.rb
Instance Method Summary collapse
-
#initialize ⇒ GenerateAppTask
constructor
A new instance of GenerateAppTask.
- #process_template(src, dest, name) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ GenerateAppTask
Returns a new instance of GenerateAppTask.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hot_potato/generate_app_task.rb', line 5 def initialize usage unless ARGV[1] name = underscore(ARGV[1]) case ARGV[0] when "sink" process_template "template_sink.rb", "#{name}.rb", classify(name) when "faucet" process_template "template_faucet.rb", "#{name}.rb", classify(name) when "worker" process_template "template_worker.rb", "#{name}.rb", classify(name) else usage end end |
Instance Method Details
#process_template(src, dest, name) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/hot_potato/generate_app_task.rb', line 26 def process_template(src, dest, name) template_file = File.open("#{File.('..', __FILE__)}/templates/#{src}") contents = "" template_file.each { |line| contents << line} result = contents.gsub("__NAME__", name) dest_file = File.new("#{APP_PATH}/app/#{dest}", "w") dest_file.write(result) dest_file.close puts "Writing #{APP_PATH}/app/#{dest}" end |
#usage ⇒ Object
21 22 23 24 |
# File 'lib/hot_potato/generate_app_task.rb', line 21 def usage puts "Usage: generate [faucet|worker|sink] name" exit 1 end |