lib/gooddata/commands/scaffold.rb in gooddata-0.6.0.pre11 vs lib/gooddata/commands/scaffold.rb in gooddata-0.6.0

- old
+ new

@@ -1,61 +1,63 @@ +# encoding: UTF-8 + +require 'erubis' +require 'fileutils' + module GoodData::Command class Scaffold - class << self + TEMPLATES_PATH = Pathname(__FILE__) + '../../../templates' + class << self + # Scaffolds new project + # TODO: Add option for custom output dir def project(name) - require 'erubis' - require 'fileutils' + fail ArgumentError, 'No name specified' if name.nil? - templates_path = Pathname(__FILE__) + "../../../templates" - FileUtils.mkdir(name) FileUtils.cd(name) do - FileUtils.mkdir("model") - FileUtils.cd("model") do - input = File.read(templates_path + 'project/model/model.rb.erb') + FileUtils.mkdir('model') + FileUtils.cd('model') do + input = File.read(TEMPLATES_PATH + 'project/model/model.rb.erb') eruby = Erubis::Eruby.new(input) - File.open("model.rb", 'w') do |f| + File.open('model.rb', 'w') do |f| f.write(eruby.result(:name => name)) end end - FileUtils.mkdir("data") - FileUtils.cd("data") do - FileUtils.cp(Dir.glob(templates_path + 'project/data/*.csv'), ".") + FileUtils.mkdir('data') + FileUtils.cd('data') do + FileUtils.cp(Dir.glob(TEMPLATES_PATH + 'project/data/*.csv'), '.') end - input = File.read(templates_path + 'project/Goodfile.erb') + input = File.read(TEMPLATES_PATH + 'project/Goodfile.erb') eruby = Erubis::Eruby.new(input) - File.open("Goodfile", 'w') do |f| + File.open('Goodfile', 'w') do |f| f.write(eruby.result()) end end end + # Scaffolds new brick + # TODO: Add option for custom output dir def brick(name) - - require 'erubis' - require 'fileutils' - - templates_path = Pathname(__FILE__) + "../../../templates" - + fail ArgumentError, 'No name specified' if name.nil? + FileUtils.mkdir(name) FileUtils.cd(name) do - input = File.read(templates_path + 'bricks/brick.rb.erb') + input = File.read(TEMPLATES_PATH + 'bricks/brick.rb.erb') eruby = Erubis::Eruby.new(input) - File.open("brick.rb", 'w') do |f| + File.open('brick.rb', 'w') do |f| f.write(eruby.result()) end - - input = File.read(templates_path + 'bricks/main.rb.erb') + + input = File.read(TEMPLATES_PATH + 'bricks/main.rb.erb') eruby = Erubis::Eruby.new(input) - File.open("main.rb", 'w') do |f| + File.open('main.rb', 'w') do |f| f.write(eruby.result()) end end end - end end end \ No newline at end of file