~charmers/charms/precise/rails/trunk

« back to all changes in this revision

Viewing changes to cookbooks/juju/libraries/juju/ruby_helpers.rb

  • Committer: Mark Mims
  • Date: 2013-08-29 17:47:43 UTC
  • mfrom: (9.1.5 rack)
  • Revision ID: mark.mims@canonical.com-20130829174743-ltmqllm9nkbfzqpa
merging ~pavel-pachkovskij/charms/precise/rack/trunk as per https://code.launchpad.net/~pavel-pachkovskij/charms/precise/rack/trunk/+merge/179721

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'shellwords'
 
2
require 'dotenv'
 
3
require 'foreman/procfile'
 
4
 
 
5
module RubyHelpers
 
6
  def run(command)
 
7
    value = %x{ #{command} 2>&1 }.strip
 
8
    value.empty? ? nil : value
 
9
  end
 
10
 
 
11
  def run_with_wrap_bundle(commands)
 
12
    run(wrap_bundle(commands))
 
13
  end
 
14
 
 
15
  def wrap_bundle(commands)
 
16
    [
 
17
      'unset BUNDLE_GEMFILE RUBYOPT GEM_HOME',
 
18
      hash_to_shell_args(dotenv_args).map{ |args| "export #{args}" },
 
19
      commands
 
20
    ].flatten.join(';')
 
21
  end
 
22
 
 
23
  def shell_quote(value)
 
24
    Shellwords.escape(value)
 
25
  end
 
26
 
 
27
  def hash_to_shell_args(hash)
 
28
    hash.map { |key, value| "#{key}=#{value}" }
 
29
  end
 
30
 
 
31
  def dotenv_args
 
32
    ::File.exists?(dotenv_path) ? Dotenv::Environment.new(dotenv_path) : {}
 
33
  end
 
34
private
 
35
  def dotenv_path
 
36
    "#{node[:rack][:root]}/shared/.env"
 
37
  end
 
38
end
 
 
b'\\ No newline at end of file'