Class: RailsConsolePro::DiffResult

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_console_pro/diff_result.rb

Overview

Value object for object comparison results

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object1:, object2:, differences: {}, identical: false, object1_type: nil, object2_type: nil, timestamp: Time.current) ⇒ DiffResult

Returns a new instance of DiffResult.



9
10
11
12
13
14
15
16
17
18
# File 'lib/rails_console_pro/diff_result.rb', line 9

def initialize(object1:, object2:, differences: {}, identical: false,
               object1_type: nil, object2_type: nil, timestamp: Time.current)
  @object1 = object1
  @object2 = object2
  @differences = differences
  @identical = identical
  @object1_type = object1_type || object1.class.name
  @object2_type = object2_type || object2.class.name
  @timestamp = timestamp
end

Instance Attribute Details

#differencesObject (readonly)

Returns the value of attribute differences.



6
7
8
# File 'lib/rails_console_pro/diff_result.rb', line 6

def differences
  @differences
end

#identicalObject (readonly)

Returns the value of attribute identical.



6
7
8
# File 'lib/rails_console_pro/diff_result.rb', line 6

def identical
  @identical
end

#object1Object (readonly)

Returns the value of attribute object1.



6
7
8
# File 'lib/rails_console_pro/diff_result.rb', line 6

def object1
  @object1
end

#object1_typeObject (readonly)

Returns the value of attribute object1_type.



6
7
8
# File 'lib/rails_console_pro/diff_result.rb', line 6

def object1_type
  @object1_type
end

#object2Object (readonly)

Returns the value of attribute object2.



6
7
8
# File 'lib/rails_console_pro/diff_result.rb', line 6

def object2
  @object2
end

#object2_typeObject (readonly)

Returns the value of attribute object2_type.



6
7
8
# File 'lib/rails_console_pro/diff_result.rb', line 6

def object2_type
  @object2_type
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



6
7
8
# File 'lib/rails_console_pro/diff_result.rb', line 6

def timestamp
  @timestamp
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
# File 'lib/rails_console_pro/diff_result.rb', line 20

def ==(other)
  other.is_a?(self.class) && other.object1 == object1 && other.object2 == object2
end

#diff_countObject



32
33
34
# File 'lib/rails_console_pro/diff_result.rb', line 32

def diff_count
  differences.size
end

#different_types?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rails_console_pro/diff_result.rb', line 28

def different_types?
  object1_type != object2_type
end

#export_to_file(file_path, format: nil) ⇒ Object

Export to file



52
53
54
# File 'lib/rails_console_pro/diff_result.rb', line 52

def export_to_file(file_path, format: nil)
  FormatExporter.export_to_file(self, file_path, format: format)
end

#has_differences?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rails_console_pro/diff_result.rb', line 24

def has_differences?
  !identical && differences.any?
end

#to_html(style: :default) ⇒ Object

Export to HTML



47
48
49
# File 'lib/rails_console_pro/diff_result.rb', line 47

def to_html(style: :default)
  FormatExporter.to_html(self, title: "Diff Comparison", style: style)
end

#to_json(pretty: true) ⇒ Object

Export to JSON



37
38
39
# File 'lib/rails_console_pro/diff_result.rb', line 37

def to_json(pretty: true)
  FormatExporter.to_json(self, pretty: pretty)
end

#to_yamlObject

Export to YAML



42
43
44
# File 'lib/rails_console_pro/diff_result.rb', line 42

def to_yaml
  FormatExporter.to_yaml(self)
end