class SyncWrap::Bundle

Provision to `bundle install`, optionally triggered by a state change key.

Host component dependencies: RunUser?, SourceTree?, BundlerGem

Attributes

bundle_install_bin_stubs[RW]

The path to install bin stubs, if any. If relative, it is relative to bundle_path. (Default: sbin; directory in bundle_path) The default is purposefully not 'bin', so as to avoid clashes with source trees that already have a 'bin', for example that contain gem source as well.

bundle_install_env[RW]

Hash of environment key/values to set on call to bundle install (Default: {} -> none)

bundle_install_path[RW]

The path to bundle install dependencies. If relative, it is relative to bundle_path. (Default: ~/.gem -> the bundle_install_user gems)

bundle_install_user[W]

User to perform the bundle install (Default: SyncWrap::RunUser#run_user)

bundle_path[W]

Path to the Gemfile(.lock) (Default: SyncWrap::SourceTree#remote_source_path)

Public Class Methods

new( opts = {} ) click to toggle source
Calls superclass method SyncWrap::ChangeKeyListener.new
# File lib/syncwrap/components/bundle.rb, line 69
def initialize( opts = {} )
  @bundle_path = nil
  @bundle_install_env = {}
  @bundle_install_path = '~/.gem'
  @bundle_install_user = nil
  @bundle_install_bin_stubs = 'sbin'
  super
end

Public Instance Methods

bundle_install() click to toggle source
# File lib/syncwrap/components/bundle.rb, line 82
def bundle_install
  sh( "( cd #{bundle_path}", close: ')', user: bundle_install_user ) do
    cmd = [ preamble, bundle_command, '_' + bundler_version + '_', 'install' ]

    if bundle_install_path
      cmd += [ '--path', bundle_install_path ]
    end

    if bundle_install_bin_stubs
      cmd += [ '--binstubs', bundle_install_bin_stubs ]
    end

    sh( cmd.join(' '), user: bundle_install_user )
  end
end
bundle_path() click to toggle source
# File lib/syncwrap/components/bundle.rb, line 36
def bundle_path
  @bundle_path || remote_source_path
end
install() click to toggle source
# File lib/syncwrap/components/bundle.rb, line 78
def install
  bundle_install if change_key.nil? || change_key_changes?
end

Protected Instance Methods

bundle_install_user() click to toggle source
# File lib/syncwrap/components/bundle.rb, line 58
def bundle_install_user
  @bundle_install_user || run_user
end
preamble() click to toggle source
# File lib/syncwrap/components/bundle.rb, line 100
def preamble
  setters = bundle_install_env.map do |k,v|
    k.to_s + '="' + v.gsub( /["\]/ ) { |c| '\' + c } + '"'
  end
  setters.join( ' ' )
end