Class: RailsPwnerer::App::Gems

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/rails_pwnerer/app/gems.rb

Overview

sets up the application gems

Instance Method Summary collapse

Methods included from Base

_setup_unix, _setup_windows, all_packages, all_packages_without_caching, #atomic_erase, #atomic_read, #atomic_write, #best_package_matching, #check_rails_root, #control_boot_script, #cpu_cores, #current_user, #gem_exists?, #gid_for_username, #group_for_username, #hook_boot_script, #install_gem, #install_gems, #install_package, #install_package_impl, #install_package_matching, #install_packages, #kill_tree, #os_distro, package_info_hash, #path_to_boot_script, #path_to_boot_script_defaults, #path_to_gemdir, #process_info, #prompt_user_for_password, #remove_package, #remove_packages, #search_packages, #uid_for_username, #unroll_collection, #update_all_packages, #update_all_packages_impl, #update_gems, #update_package_metadata, #upgrade_gem, #upgrade_gems, #upgrade_package, #upgrade_package_impl, #upgrade_packages, #with_package_source, #with_temp_dir

Instance Method Details

#manage(app_name, instance_name, action) ⇒ Object



39
40
41
42
43
# File 'lib/rails_pwnerer/app/gems.rb', line 39

def manage(app_name, instance_name, action)
  # Called when an app is rolled back, to get the old gems reinstalled,
  # if necessary.
  update(app_name, instance_name)
end

#setup(app_name, instance_name) ⇒ Object



45
46
47
# File 'lib/rails_pwnerer/app/gems.rb', line 45

def setup(app_name, instance_name)
  update(app_name, instance_name)
end

#update(app_name, instance_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rails_pwnerer/app/gems.rb', line 6

def update(app_name, instance_name)
  app_config = RailsPwnerer::Config[app_name, instance_name]

  Dir.chdir app_config[:app_path] do
    # Phase 1: app-directed install
    if !File.exist?('Gemfile') && app_config[:gems]
      # Can be specified as comma-separated string or array.
      if app_config[:gems].respond_to? :to_str
        install_gems = app_config[:gems].split(',')
      else
        install_gems = app_config[:gems]
      end
      install_gems.each do |gem_name|
        begin
          install_gem gem_name unless gem_exists? gem_name
        rescue Exception
        end
      end
    end

    # Phase 2: bundler / rails install
    # Install the gems needed by the app.
    if File.exist? 'Gemfile'
      unless /^\s+gem\s+['"]thin['"]/ =~ File.read('Gemfile')
        File.open('Gemfile', 'a') { |f| f.write "\ngem 'thin'\n"}
      end
      Kernel.system "bundle install --without development test"
    else
      Kernel.system "rake gems:install RAILS_ENV=production"
    end
  end
end