Class: QuickSync::RSync
- Inherits:
-
Object
- Object
- QuickSync::RSync
- Defined in:
- lib/quicksync/rsync.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#copy_options ⇒ Object
Returns the value of attribute copy_options.
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
-
#dest ⇒ Object
Returns the value of attribute dest.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#host ⇒ Object
Returns the value of attribute host.
-
#include ⇒ Object
Returns the value of attribute include.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#run_method ⇒ Object
Returns the value of attribute run_method.
-
#run_on ⇒ Object
Returns the value of attribute run_on.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#src ⇒ Object
Returns the value of attribute src.
-
#sync_type ⇒ Object
readonly
Returns the value of attribute sync_type.
-
#sync_types ⇒ Object
Returns the value of attribute sync_types.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #copy_local(src, dest, options = {}) ⇒ Object
- #copy_options_to_s ⇒ Object
- #copy_remote(src, dest, options = {}) ⇒ Object
- #dest_fully_qualified ⇒ Object
- #exclude_to_s ⇒ Object
- #generate_cmd ⇒ Object
- #include_to_s ⇒ Object
-
#initialize ⇒ RSync
constructor
A new instance of RSync.
- #parse_options(src, dest, options) ⇒ Object
- #pull_from(src, dest, options = {}) ⇒ Object
- #push_to(src, dest, options = {}) ⇒ Object
- #set_sync_type(sync_type) ⇒ Object
- #src_fully_qualified ⇒ Object
- #sync(src, dest, options = {}) ⇒ Object
- #to_str ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/quicksync/rsync.rb', line 5 def config @config end |
#copy_options ⇒ Object
Returns the value of attribute copy_options.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def @copy_options end |
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
5 6 7 |
# File 'lib/quicksync/rsync.rb', line 5 def @default_options end |
#dest ⇒ Object
Returns the value of attribute dest.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def dest @dest end |
#exclude ⇒ Object
Returns the value of attribute exclude.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def exclude @exclude end |
#host ⇒ Object
Returns the value of attribute host.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def host @host end |
#include ⇒ Object
Returns the value of attribute include.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def include @include end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/quicksync/rsync.rb', line 5 def logger @logger end |
#run_method ⇒ Object
Returns the value of attribute run_method.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def run_method @run_method end |
#run_on ⇒ Object
Returns the value of attribute run_on.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def run_on @run_on end |
#settings ⇒ Object
Returns the value of attribute settings.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def settings @settings end |
#src ⇒ Object
Returns the value of attribute src.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def src @src end |
#sync_type ⇒ Object (readonly)
Returns the value of attribute sync_type.
5 6 7 |
# File 'lib/quicksync/rsync.rb', line 5 def sync_type @sync_type end |
#sync_types ⇒ Object
Returns the value of attribute sync_types.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def sync_types @sync_types end |
#user ⇒ Object
Returns the value of attribute user.
4 5 6 |
# File 'lib/quicksync/rsync.rb', line 4 def user @user end |
Instance Method Details
#copy_local(src, dest, options = {}) ⇒ Object
46 47 48 49 |
# File 'lib/quicksync/rsync.rb', line 46 def copy_local(src,dest,={}) set_sync_type(__method__) return sync(src,dest,) end |
#copy_options_to_s ⇒ Object
110 111 112 |
# File 'lib/quicksync/rsync.rb', line 110 def return .map{ |o| "--#{o}"}.join(' ') end |
#copy_remote(src, dest, options = {}) ⇒ Object
51 52 53 54 |
# File 'lib/quicksync/rsync.rb', line 51 def copy_remote(src,dest,={}) set_sync_type(__method__) return sync(src,dest,) end |
#dest_fully_qualified ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/quicksync/rsync.rb', line 23 def dest_fully_qualified if sync_type == :pull_from || sync_type == :push_to return "#{user}@#{host}:#{dest}" else return "#{dest}" end end |
#exclude_to_s ⇒ Object
120 121 122 123 124 |
# File 'lib/quicksync/rsync.rb', line 120 def exclude_to_s if exclude.any? return exclude.map { |e| "--exclude=\"#{e}\"" }.join(' ') end end |
#generate_cmd ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/quicksync/rsync.rb', line 126 def generate_cmd cmd = "#{settings[:rsync_app]} #{}" cmd << " #{include_to_s}" if !include.nil? && include.any? cmd << " #{exclude_to_s}" if !exclude.nil? && exclude.any? cmd << " #{src_fully_qualified}/ #{dest_fully_qualified}" return cmd end |
#include_to_s ⇒ Object
114 115 116 117 118 |
# File 'lib/quicksync/rsync.rb', line 114 def include_to_s if include.any? return include.map { |i| "--include=\"#{i}\"" }.join(' ') end end |
#parse_options(src, dest, options) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/quicksync/rsync.rb', line 86 def (src,dest,) if src.nil? || src.empty? raise ArgumentError, ":src can not be empty" end if dest.nil? || dest.empty? raise ArgumentError, ":dest can not be empty" end @src = ( ! src.nil? && ! src.empty? ) ? src: [:src] @dest = ( ! dest.nil? && ! dest.empty? ) ? dest: [:dest] @host = ( ! host.nil? && ! host.empty? ) ? host: [:host] @user = ( ! user.nil? && ! user.empty? ) ? user: [:user] @exclude = .length > 0 && ! [:exclude].nil? ? [:exclude]: [:exclude] @include = .length > 0 && ! [:include].nil? ? [:include]: [:include] @copy_options = .length > 0 && ! [:copy_options].nil? ? [:copy_options]: [:copy_options] @settings = .length > 0 && ! [:settings].nil? ? [:settings].merge([:settings]): [:settings] @run_method = .length > 0 && ! [:run_method].nil? ? [:run_method]: [:run_method] # logger.important " parse_options: #{self.to_str}" end |
#pull_from(src, dest, options = {}) ⇒ Object
36 37 38 39 |
# File 'lib/quicksync/rsync.rb', line 36 def pull_from(src,dest,={}) set_sync_type(__method__) return sync(src,dest,) end |
#push_to(src, dest, options = {}) ⇒ Object
41 42 43 44 |
# File 'lib/quicksync/rsync.rb', line 41 def push_to(src,dest,={}) set_sync_type(__method__) return sync(src,dest,) end |
#set_sync_type(sync_type) ⇒ Object
14 15 16 |
# File 'lib/quicksync/rsync.rb', line 14 def set_sync_type(sync_type) @sync_type = sync_type.to_sym end |
#src_fully_qualified ⇒ Object
19 20 21 |
# File 'lib/quicksync/rsync.rb', line 19 def src_fully_qualified return src end |
#sync(src, dest, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/quicksync/rsync.rb', line 56 def sync(src,dest,={}) (src,dest,) cmd = generate_cmd # logger.info "quicksync command:\n #{cmd}" if run_method == :execute logger.info " RSync.pull_from: executing command:\n# {cmd}" system(cmd) end return cmd end |
#to_str ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/quicksync/rsync.rb', line 68 def to_str out = "RSync.to_str:\n" out += " :src=#{src}\n" out += " :dest=#{dest}\n" out += " :dest_fully_qualified=#{dest_fully_qualified}\n" out += " :host=#{host}\n" out += " :user=#{user}\n" out += " :exclude=#{exclude.join(',')}\n" if ! exclude.nil? out += " :include=#{include.join(',')}\n" if ! include.nil? out += " :copy_options=#{.join(" --")}\n" out += " :settings=#{settings}\n" out += " :sync_type=#{sync_type}\n" out += " :sync_types=#{sync_types}\n" out += " :run_on=#{run_on}\n" out += " :run_method=#{run_method}\n" return out end |