Class: ODisk::Diff
- Inherits:
-
Object
- Object
- ODisk::Diff
- Defined in:
- lib/odisk/diff.rb
Instance Attribute Summary collapse
-
#local ⇒ Object
local Info Object.
-
#remote ⇒ Object
remote Info Object.
-
#sub_diffs ⇒ Object
Returns the value of attribute sub_diffs.
Class Method Summary collapse
Instance Method Summary collapse
- #fill_hash(prefix, h, sym = false) ⇒ Object
-
#initialize(local, remote, sub_diffs = {}) ⇒ Diff
constructor
A new instance of Diff.
- #to_s ⇒ Object
Constructor Details
#initialize(local, remote, sub_diffs = {}) ⇒ Diff
Returns a new instance of Diff.
47 48 49 50 51 |
# File 'lib/odisk/diff.rb', line 47 def initialize(local, remote, sub_diffs={}) @local = local @remote = remote @sub_diffs = sub_diffs end |
Instance Attribute Details
#local ⇒ Object
local Info Object
5 6 7 |
# File 'lib/odisk/diff.rb', line 5 def local @local end |
#remote ⇒ Object
remote Info Object
7 8 9 |
# File 'lib/odisk/diff.rb', line 7 def remote @remote end |
#sub_diffs ⇒ Object
Returns the value of attribute sub_diffs.
9 10 11 |
# File 'lib/odisk/diff.rb', line 9 def sub_diffs @sub_diffs end |
Class Method Details
.digest_diff(ld, rd) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/odisk/diff.rb', line 34 def self.digest_diff(ld, rd) diffs = {} lh = ld.entries_hash() rh = rd.entries_hash() keys = lh.keys | rh.keys keys.each do |k| le = lh[k] re = rh[k] diffs[k] = self.new(le, re) unless le == re end diffs end |
.dir_diff(l, r, recursive = false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/odisk/diff.rb', line 11 def self.dir_diff(l, r, recursive=false) ld = Digest.create(l, nil) rd = Digest.create(r, nil) diffs = digest_diff(ld, rd) if recursive lh = ld.entries_hash() rh = rd.entries_hash() keys = lh.keys | rh.keys keys.each do |k| next unless lh[k].is_a?(::ODisk::Dir) || rh[k].is_a?(::ODisk::Dir) unless (sd = dir_diff(::File.join(l, k), ::File.join(r, k))).nil? || sd.empty? if (d = diffs[k]).nil? d = self.new(lh[k], rh[k], sd) else d.sub_diffs = sd end diffs[k] = d end end end diffs end |
Instance Method Details
#fill_hash(prefix, h, sym = false) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/odisk/diff.rb', line 53 def fill_hash(prefix, h, sym=false) [:class, :name, :owner, :group, :mode, :mtime, :size, :target].each do |m| next unless @local.respond_to?(m) and @remote.respond_to?(m) lv = @local.send(m) rv = @remote.send(m) if sym k = m else k = @local.name + '.' + m.to_s k = prefix + '.' + k unless prefix.nil? end h[k] = [lv, rv] unless lv == rv unless (:mtime == m && !@remote.is_a?(::ODisk::File)) end unless @local.nil? pre = prefix.nil? ? @local.name : (prefix + '.' + @local.name) end @sub_diffs.each do |name,d| d.fill_hash(pre, h) end end |
#to_s ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/odisk/diff.rb', line 74 def to_s() s = '' h = {} fill_hash(nil, h) h.each { |k,v| s << "#{k}: #{v[0]} vs #{v[1]}\n" } s end |