module MoodeAutoDeployKit::ScriptProvider

Public Instance Methods

create_script(root_dir) click to toggle source
# File lib/moode_auto_deploy_kit/script_provider.rb, line 7
def create_script root_dir
  puts "Creating scripts to #{root_dir}"
  app_root_dir = File.join(root_dir, 'app')
  server_root_dir = File.join(root_dir, 'server')

  copy_templates_to_working_dir
  render_templates_according_to_config
  copy_generated_scripts_to_target_dir root_dir
  modify_server_gemfile server_root_dir
end

Private Instance Methods

copy_generated_scripts_to_target_dir(root_dir) click to toggle source
# File lib/moode_auto_deploy_kit/script_provider.rb, line 42
def copy_generated_scripts_to_target_dir root_dir
  FileUtils.cp_r "#{$fs.deploy_script_working_dir}/.", root_dir
  FileUtils.rm_rf $fs.working
end
copy_templates_to_working_dir() click to toggle source
# File lib/moode_auto_deploy_kit/script_provider.rb, line 30
def copy_templates_to_working_dir
  working_dir = $fs.deploy_script_working_dir
  reset_dir working_dir
  FileUtils.cp_r "#{$fs.deploy_script_template_dir}/.", working_dir
end
get_template_list(dir, templates) click to toggle source
# File lib/moode_auto_deploy_kit/script_provider.rb, line 54
def get_template_list(dir, templates)
  Dir.foreach(dir) do |entry|
    absolute_path = File.join(dir, entry)
    next if (entry == "." || entry == "..")
    templates << absolute_path if File.file?(absolute_path)
    get_template_list(absolute_path, templates) if File.directory?(absolute_path)
  end
end
modify_server_gemfile(server_root_dir) click to toggle source
# File lib/moode_auto_deploy_kit/script_provider.rb, line 20
def modify_server_gemfile server_root_dir
  extra_server_gems = IO.readlines($fs.server_gemfile).join
  target_server_gem_file = File.join(server_root_dir, 'Gemfile')
  gemfile_content  = IO.readlines(target_server_gem_file).join
  unless gemfile_content.include? extra_server_gems
    gemfile_content += extra_server_gems
  end
  File.open(target_server_gem_file, 'w') { |file| file.write(gemfile_content) }
end
render_template(template_file, config) click to toggle source
# File lib/moode_auto_deploy_kit/script_provider.rb, line 47
def render_template(template_file, config)
  puts "Rendering template #{template_file}"
  template = ERB.new(IO.readlines(template_file).join)      
  script_content = template.result($config.get_binding)
  File.open(template_file, 'w') { |file| file.write(script_content) }
end
render_templates_according_to_config() click to toggle source
# File lib/moode_auto_deploy_kit/script_provider.rb, line 36
def render_templates_according_to_config
  templates = [] 
  get_template_list($fs.deploy_script_working_dir, templates)
  templates.each { |template| render_template(template, $config) }
end