Class: AbideDevUtils::XCCDF::Diff::ChangeSet
- Inherits:
-
Object
- Object
- AbideDevUtils::XCCDF::Diff::ChangeSet
- Defined in:
- lib/abide_dev_utils/xccdf/diff.rb
Overview
Represents a change in a diff.
Instance Attribute Summary collapse
-
#change ⇒ Object
readonly
Returns the value of attribute change.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#value_to ⇒ Object
readonly
Returns the value of attribute value_to.
Instance Method Summary collapse
- #can_merge?(other) ⇒ Boolean
-
#initialize(change:, key:, value:, value_to: nil) ⇒ ChangeSet
constructor
A new instance of ChangeSet.
- #merge(other) ⇒ Object
- #merge!(other) ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(change:, key:, value:, value_to: nil) ⇒ ChangeSet
Returns a new instance of ChangeSet.
22 23 24 25 26 27 28 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 22 def initialize(change:, key:, value:, value_to: nil) validate_change(change) @change = change @key = key @value = value @value_to = value_to end |
Instance Attribute Details
#change ⇒ Object (readonly)
Returns the value of attribute change.
20 21 22 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 20 def change @change end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
20 21 22 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 20 def key @key end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
20 21 22 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 20 def value @value end |
#value_to ⇒ Object (readonly)
Returns the value of attribute value_to.
20 21 22 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 20 def value_to @value_to end |
Instance Method Details
#can_merge?(other) ⇒ Boolean
43 44 45 46 47 48 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 43 def can_merge?(other) return false unless (change == '-' && other.change == '+') || (change == '+' && other.change == '-') return false unless key == other.key || value_hash_equality(other) true end |
#merge(other) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 50 def merge(other) unless can_merge?(other) raise ArgumentError, 'Cannot merge. Possible causes: change is identical; key or value do not match' end new_to_value = value == other.value ? nil : other.value ChangeSet.new( change: '~', key: key, value: value, value_to: new_to_value ) end |
#merge!(other) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 64 def merge!(other) new_props = merge(other) @change = new_props.change @key = new_props.key @value = new_props.value @value_to = new_props.value_to end |
#to_h ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 34 def to_h { change: change, key: key, value: value, value_to: value_to, } end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 30 def to_s value_change_string(value, value_to) end |