Class: JGrouper::ExportFileDiff

Inherits:
Object
  • Object
show all
Defined in:
lib/jgrouper/export_file_diff.rb

Overview

JGrouper::ExportFileDiff - Difference between two JGrouper::ExportFileEntry objects

WARNING

The output format is unstable and will change in a future release.

USAGE

require 'jgrouper'
require 'jgrouper/export_file_diff'
require 'jgrouper/export_file_entry'

diff = JGrouper::ExportFileDiff JGrouper::ExportFileEntry.new(json), JGrouper::ExportFileEntry.new(json)

Instance Method Summary collapse

Constructor Details

#initialize(src, dst) ⇒ ExportFileDiff

Returns a new instance of ExportFileDiff.



22
23
24
25
26
27
# File 'lib/jgrouper/export_file_diff.rb', line 22

def initialize(src, dst)
  @dst  = dst
  @key  = dst.key || src.key
  @src  = src
  @diff = HashDiff.diff @src.json, @dst.json
end

Instance Method Details

#different?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/jgrouper/export_file_diff.rb', line 29

def different?
  !@diff.empty?
end

#to_hashObject



37
38
39
40
# File 'lib/jgrouper/export_file_diff.rb', line 37

def to_hash
  return {} unless different?
  return { entry: @key, changes: @diff }
end

#to_jsonObject



42
43
44
# File 'lib/jgrouper/export_file_diff.rb', line 42

def to_json
  to_hash.to_json
end

#to_sObject



33
34
35
# File 'lib/jgrouper/export_file_diff.rb', line 33

def to_s
  { key: @key, diff: @diff }.inspect
end