Class: QuickSync::RSync
- Inherits:
-
Object
- Object
- QuickSync::RSync
- Defined in:
- lib/quicksync/rsync.rb
Instance Attribute Summary collapse
-
#copy_options ⇒ Object
Returns the value of attribute copy_options.
-
#default_options ⇒ Object
readonly
Returns the value of attribute default_options.
-
#exclude ⇒ Object
Returns the value of attribute exclude.
-
#from ⇒ Object
Returns the value of attribute from.
-
#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.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#to ⇒ Object
Returns the value of attribute to.
Instance Method Summary collapse
- #copy_options_to_s ⇒ Object
- #exclude_to_s ⇒ Object
- #from_to_s ⇒ Object
- #generate_cmd ⇒ Object
- #include_to_s ⇒ Object
-
#initialize ⇒ RSync
constructor
A new instance of RSync.
- #is_local(the_host) ⇒ Object
- #is_remote(the_host) ⇒ Object
- #parse_options(from_v, to_v, options) ⇒ Object
- #pull_from(from, to, options = {}) ⇒ Object
- #push_to(from, to, options = {}) ⇒ Object
- #run_on ⇒ Object
- #to_to_s ⇒ Object
Constructor Details
Instance Attribute Details
#copy_options ⇒ Object
Returns the value of attribute copy_options.
6 7 8 |
# File 'lib/quicksync/rsync.rb', line 6 def @copy_options end |
#default_options ⇒ Object (readonly)
Returns the value of attribute default_options.
7 8 9 |
# File 'lib/quicksync/rsync.rb', line 7 def @default_options end |
#exclude ⇒ Object
Returns the value of attribute exclude.
6 7 8 |
# File 'lib/quicksync/rsync.rb', line 6 def exclude @exclude end |
#from ⇒ Object
Returns the value of attribute from.
6 7 8 |
# File 'lib/quicksync/rsync.rb', line 6 def from @from end |
#include ⇒ Object
Returns the value of attribute include.
6 7 8 |
# File 'lib/quicksync/rsync.rb', line 6 def include @include end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/quicksync/rsync.rb', line 7 def logger @logger end |
#run_method ⇒ Object
Returns the value of attribute run_method.
6 7 8 |
# File 'lib/quicksync/rsync.rb', line 6 def run_method @run_method end |
#settings ⇒ Object
Returns the value of attribute settings.
6 7 8 |
# File 'lib/quicksync/rsync.rb', line 6 def settings @settings end |
#to ⇒ Object
Returns the value of attribute to.
6 7 8 |
# File 'lib/quicksync/rsync.rb', line 6 def to @to end |
Instance Method Details
#copy_options_to_s ⇒ Object
16 17 18 |
# File 'lib/quicksync/rsync.rb', line 16 def return .map{ |o| "--#{o}"}.join(' ') end |
#exclude_to_s ⇒ Object
26 27 28 29 30 |
# File 'lib/quicksync/rsync.rb', line 26 def exclude_to_s if exclude.any? return exclude.map { |e| "--exclude=\"#{e}\"" }.join(' ') end end |
#from_to_s ⇒ Object
126 127 128 129 130 131 132 133 134 |
# File 'lib/quicksync/rsync.rb', line 126 def from_to_s logger.debug "RSync.from_to_s: from=#{from}" if ! from[:host].nil? && ! from[:host].empty? && ! from[:host].include?("local") return from[:user]+"@"+from[:host] + ":" + from[:dir] else return from[:dir] end end |
#generate_cmd ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/quicksync/rsync.rb', line 146 def generate_cmd logger.debug "QuickSync.generated_cmd: method called" cmd = "#{settings[:rsync_app]} #{}" cmd << " #{include_to_s}" if !include.nil? && include.any? cmd << " #{exclude_to_s}" if !exclude.nil? && exclude.any? cmd << " #{from_to_s}/ #{to_to_s}" return cmd end |
#include_to_s ⇒ Object
20 21 22 23 24 |
# File 'lib/quicksync/rsync.rb', line 20 def include_to_s if include.any? return include.map { |i| "--include=\"#{i}\"" }.join(' ') end end |
#is_local(the_host) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/quicksync/rsync.rb', line 110 def is_local(the_host) if ! the_host.nil? && ! the_host.empty? && the_host.include?("local") return true else return false end end |
#is_remote(the_host) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/quicksync/rsync.rb', line 118 def is_remote(the_host) if ! the_host.nil? && ! the_host.empty? && ! the_host.include?("local") return true else return false end end |
#parse_options(from_v, to_v, options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/quicksync/rsync.rb', line 36 def (from_v,to_v,) if from_v.nil? || from_v.empty? raise ArgumentError, ":from can not be empty" end if to_v.nil? || to_v.empty? raise ArgumentError, ":to can not be empty" end logger.debug "QuickSync.parse_options: from class=#{from_v.class}" @from = from_v == String ? [:from].merge({:dir=>from_v}): [:from].merge(from_v) @to = to_v == String ? [:to].merge({:dir=>to_v}): [:to].merge(to_v) @exclude = .length > 0 && ! [:exclude].nil? ? [:exclude]: [:exclude] @include = .length > 0 && ! [:include].nil? ? [:include]: [:include] @copy_options = .length > 0 && ! [:copy_options].nil? ? [:copy_options].concat([:copy_options]).uniq!: [:copy_options] @settings = .length > 0 && ! [:settings].nil? ? [:settings].merge([:settings]): [:settings] @run_method = [:run_method] logger.debug "QuickSync.parse_options:" logger.debug " from=#{from}" logger.debug " to=#{to}" logger.debug " exclude=#{exclude}" logger.debug " include=#{include}" logger.debug " copy_options=#{}" logger.debug " settings=#{settings}" end |
#pull_from(from, to, options = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/quicksync/rsync.rb', line 66 def pull_from(from,to,={}) (from,to,) # if from[:dir] does not exist then abort as there is nothing to do cmd = generate_cmd logger.info "RSync.pull_from: run_method=#{run_method}" if run_method == :execute # run the actual command before returning it logger.info "RSync.pull_from: about to execute command" system(cmd) end logger.info "quicksync command:\n #{cmd}" return cmd end |
#push_to(from, to, options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/quicksync/rsync.rb', line 81 def push_to(from,to,={}) (from,to,) # if from[:dir] does not exist then abort as there is nothing to do cmd = generate_cmd logger.info "RSync.push_to: run_method=#{run_method}" if run_method == :execute # run the actual command before returning it logger.info "RSync.push_to: about to execute command" system(cmd) end logger.info "quicksync command:\n #{cmd}" return cmd end |
#run_on ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/quicksync/rsync.rb', line 96 def run_on if is_local(from[:host]) && is_local(to[:host]) return :local elsif is_local(from[:host]) && is_remote(to[:host]) return :local elsif is_remote(from[:host]) && is_remote(to[:host]) return :remote elsif is_remote(from[:host]) && is_local(to[:host]) return :remote else return :local end end |
#to_to_s ⇒ Object
136 137 138 139 140 141 142 143 |
# File 'lib/quicksync/rsync.rb', line 136 def to_to_s val = to[:dir] if ! to[:host].nil? && ! to[:host].empty? && ! to[:host].include?("local") val = to[:user]+"@"+to[:host] + ":" + to[:dir] else return to[:dir] end end |