class SyncWrap::SourceTree
Install/synchronize a source tree to remotes via rput. By default assumes the local source tree is in a Git DVCS repository and checks that it is clean before executing.
The remote source directory will be owned by the SyncWrap::RunUser#run_user
Attributes
The state key (or Array of keys) to set to if there are any changes to the tree (Default: :source_tree)
Local path to root directory in which source_dir is found (Default: <sync-file directory>/..)
A file name found at the root of #source_dir containing the complete list of files to transfer. The value `true` is a synonym for 'Manifest.txt'. (Default: nil -> none)
Remote directory name (Default: source_dir)
File mode as integer for the remote_dir (Default: 0755)
Remote path to the root directory in which remote_dir should be installed. (Default: SyncWrap::RunUser#run_dir)
Require local #source_dir to be clean per Git before rput of the tree. (Default: true)
Any additional options for the rput (Default: {} -> none)
Source directory name (required)
Public Class Methods
# File lib/syncwrap/components/source_tree.rb, line 84 def initialize( opts = {} ) opts = opts.dup clr = opts.delete(:caller) || caller @local_source_root = path_relative_to_caller( '..', clr ) @source_dir = nil @remote_dir = nil @remote_dir_mode = 0755 @remote_source_root = nil @require_clean = true @rput_options = {} @change_key = :source_tree @manifest = nil super raise "SourceTree#source_dir not set" unless source_dir end
Public Instance Methods
# File lib/syncwrap/components/source_tree.rb, line 105 def install mkdir_run_user( remote_source_path, mode: remote_dir_mode ) changes = sync_source on_change( changes ) unless changes.empty? changes end
# File lib/syncwrap/components/source_tree.rb, line 52 def remote_dir @remote_dir || source_dir end
# File lib/syncwrap/components/source_tree.rb, line 101 def remote_source_path File.join( remote_source_root, remote_dir ) end
# File lib/syncwrap/components/source_tree.rb, line 45 def remote_source_root @remote_source_root || run_dir end
Protected Instance Methods
# File lib/syncwrap/components/source_tree.rb, line 114 def local_source_path File.join( local_source_root, source_dir ) end
# File lib/syncwrap/components/source_tree.rb, line 118 def on_change( changes ) unless changes.empty? || change_key.nil? Array(change_key).each do |key| state[ key ] ||= [] state[ key ] += changes end end end
# File lib/syncwrap/components/source_tree.rb, line 65 def require_clean? @require_clean end
# File lib/syncwrap/components/source_tree.rb, line 127 def sync_source GitHelp.require_clean!( local_source_path ) if require_clean? opts = { erb_process: false, excludes: [ :dev, '.bundle/' ], user: run_user, sync_paths: [ local_source_root ] } mf = manifest if mf mf = 'Manifest.txt' if mf == true mf = File.join( local_source_root, source_dir, mf ) opts[:manifest] = mf end opts.merge!( rput_options ) rput( source_dir + '/', remote_source_path, opts ) end