Class: RailsConsolePro::DiffResult
- Inherits:
-
Object
- Object
- RailsConsolePro::DiffResult
- Defined in:
- lib/rails_console_pro/diff_result.rb
Overview
Value object for object comparison results
Instance Attribute Summary collapse
-
#differences ⇒ Object
readonly
Returns the value of attribute differences.
-
#identical ⇒ Object
readonly
Returns the value of attribute identical.
-
#object1 ⇒ Object
readonly
Returns the value of attribute object1.
-
#object1_type ⇒ Object
readonly
Returns the value of attribute object1_type.
-
#object2 ⇒ Object
readonly
Returns the value of attribute object2.
-
#object2_type ⇒ Object
readonly
Returns the value of attribute object2_type.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #diff_count ⇒ Object
- #different_types? ⇒ Boolean
-
#export_to_file(file_path, format: nil) ⇒ Object
Export to file.
- #has_differences? ⇒ Boolean
-
#initialize(object1:, object2:, differences: {}, identical: false, object1_type: nil, object2_type: nil, timestamp: Time.current) ⇒ DiffResult
constructor
A new instance of DiffResult.
-
#to_html(style: :default) ⇒ Object
Export to HTML.
-
#to_json(pretty: true) ⇒ Object
Export to JSON.
-
#to_yaml ⇒ Object
Export to YAML.
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 = end |
Instance Attribute Details
#differences ⇒ Object (readonly)
Returns the value of attribute differences.
6 7 8 |
# File 'lib/rails_console_pro/diff_result.rb', line 6 def differences @differences end |
#identical ⇒ Object (readonly)
Returns the value of attribute identical.
6 7 8 |
# File 'lib/rails_console_pro/diff_result.rb', line 6 def identical @identical end |
#object1 ⇒ Object (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_type ⇒ Object (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 |
#object2 ⇒ Object (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_type ⇒ Object (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 |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/rails_console_pro/diff_result.rb', line 6 def 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_count ⇒ Object
32 33 34 |
# File 'lib/rails_console_pro/diff_result.rb', line 32 def diff_count differences.size end |
#different_types? ⇒ 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
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_yaml ⇒ Object
Export to YAML
42 43 44 |
# File 'lib/rails_console_pro/diff_result.rb', line 42 def to_yaml FormatExporter.to_yaml(self) end |