class GrapeBootstrap::Commands::AppInit
Public Class Methods
new(path, options=[])
click to toggle source
Calls superclass method
# File lib/grape_bootstrap/commands/app_init.rb, line 8 def initialize path, options=[] super path, options @dry = (options & ["--dry"]).length > 0 setup_dirs setup_base_files end
Private Instance Methods
file_from_template(template_name, sub_path=nil)
click to toggle source
# File lib/grape_bootstrap/commands/app_init.rb, line 53 def file_from_template template_name, sub_path=nil erb_binding = -> { app_name = "APP" binding } template_name = "#{sub_path}/#{template_name}" if sub_path tpl = ERB.new( File.read( "#{File.dirname(__FILE__)}/../templates/#{template_name}.erb" ) ) File.open("#{@path}/#{template_name}", 'w') do |file| file << tpl.result(erb_binding.call) end end
setup_base_files()
click to toggle source
# File lib/grape_bootstrap/commands/app_init.rb, line 39 def setup_base_files [ "Gemfile", "README.md", "application.rb", "environment.rb", "config.ru", "Rakefile" ].each do |filename| puts "Creating #{filename}" file_from_template(filename) unless @dry end end
setup_dirs()
click to toggle source
# File lib/grape_bootstrap/commands/app_init.rb, line 17 def setup_dirs { "app/api" => ["base.rb", "status.rb"], "app/helpers" => [], "app/models" => [], "config" => ["database.yml"], "config/environments" => ["development.rb"], "db/migrate" => [], "lib" => [], "docs" => [], "public" => ["index.html"] }.each do |dir, files| puts "Creating #{dir}" FileUtils.mkdir_p("#{@path}/#{dir}") unless @dry files.each do |f| puts "Creating #{dir}/#{f}" file_from_template(f, dir) unless @dry end end end