# Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee module RightConf class BundlerConfigurator DEFAULT_GEM_PATH = 'vendor/system_gems/cache' include Configurator register :bundler description 'Installs bundler and runs "bundle install"' settings :bundler_version => 'Version of bundler gem, e.g. "1.0.10"', :bundler_gem_path => 'Path to bundler gem, e.g. "vendor/system_gems/cache"' validate_has_settings :bundler_version # Install bundler if needed and run bundle install # # === Return # true:: Always return true def run_linux report_check("Checking for bundler #{bundler_version}") res = Command.execute('bundle', '--version') success = (res.output =~ /#{bundler_version}/) report_result(success) install_bundler(res.success?) unless success report_check('Installing gems') res = Command.execute('bundle', 'install', :abort_on_failure => 'Failed to install gems') report_success true end alias :run_darwin :run_linux # Not implemented on windows (no bundler gem there) # # === Raise # (Exception):: Always raise def run_windows raise "Bundler is not supported on Windows!" end protected # Install bundler from gem in cache # # === Parameters # exists(FalseClass|TrueClass):: Whether bundler is already installed # (but is the wrong version) # # === Return # true:: Always return true # # === Raise # (Exception):: If bundler gem cannot be found or installed def install_bundler(exists) if exists report_check('Uninstalling existing versions of bundler') res = Command.execute('gem', 'uninstall', 'bundler', '-a', '-x', :abort_on_failure => 'Failed to uninstall bundler') report_success end report_check("Installing bundler #{bundler_version}") bundler_gem_path DEFAULT_GEM_PATH unless bundler_gem_path bundler_file = File.join(bundler_gem_path, "bundler-#{bundler_version}.gem") report_fatal("Missing bundler gem at #{bundler_file}") unless File.exist?(bundler_file) res = Command.execute('gem','install', bundler_file, '--no-ri', '--no-rdoc', :abort_on_failure => 'Failed to install bundler') report_success true end end end