Class: Kintsugi::ConflictResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/kintsugi/conflict_resolver.rb

Class Method Summary collapse

Class Method Details

.create_nonexistent_component_when_changing_it?(path) ⇒ Boolean

Should be called when trying to apply changes to a component with path ‘path` that doesn’t exist. Returns ‘true` if the component should be created and `false` if applying the changes to it should be ignored.

Returns:

  • (Boolean)


41
42
43
44
45
46
47
48
49
# File 'lib/kintsugi/conflict_resolver.rb', line 41

def create_nonexistent_component_when_changing_it?(path)
  resolve_merge_error(
    "Trying to apply change to a component that doesn't exist at path '#{path}'",
    {
      'Create component and the components that contain it': true,
      'Ignore change to component': false
    }
  )
end

.create_nonexistent_group_when_adding_file?(containing_group_path, file_name) ⇒ Boolean

Should be called when trying to add a file with name ‘file_name` whose containing group with path `containing_group_path` doesn’t exist. Returns ‘true` if the cotaining group should be created and `false` if adding the file should be ignored.

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
# File 'lib/kintsugi/conflict_resolver.rb', line 27

def create_nonexistent_group_when_adding_file?(containing_group_path, file_name)
  resolve_merge_error(
    "Trying to add or move a file with name '#{file_name}' to a group that doesn't exist. " \
    "The group's path is '#{containing_group_path}'",
    {
      "Create group with path '#{containing_group_path}'": true,
      "Ignore adding file '#{file_name}'": false
    }
  )
end

.create_nonexistent_group_when_adding_subgroup?(containing_group_path, subgroup_name) ⇒ Boolean

Should be called when trying to add a subgroup with name ‘subgroup_name` whose containing group with path `containing_group_path` doesn’t exist. Returns ‘true` if the cotaining group should be created and `false` if adding the subgroup should be ignored.

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
# File 'lib/kintsugi/conflict_resolver.rb', line 13

def create_nonexistent_group_when_adding_subgroup?(containing_group_path, subgroup_name)
  resolve_merge_error(
    "Trying to create group '#{subgroup_name}' inside a group that doesn't exist. The " \
    "group's path is '#{containing_group_path}'",
    {
      "Create containing group with path '#{containing_group_path}'": true,
      "Ignore adding group '#{subgroup_name}'": false
    }
  )
end

.override_values_when_keys_already_exist_in_hash?(hash_name, old_hash, new_hash) ⇒ Boolean

Should be called when trying to merge ‘new_hash` into `new_hash` but `new_hash` contains keys that exist in `old_hash`. Returns `true` if the keys should be overriden from `new_hash`, `false` to keep the values from `old_hash`.

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/kintsugi/conflict_resolver.rb', line 54

def override_values_when_keys_already_exist_in_hash?(hash_name, old_hash, new_hash)
  resolve_merge_error(
    "Trying to add values to hash of attribute named '#{hash_name}': Merging hash " \
    "#{new_hash} into existing hash #{old_hash} but it contains values that already " \
    "exist",
    {
      'Override values from new hash': true,
      'Ignore values from new hash': false
    }
  )
end

.remove_component_when_unexpected_hash?(component, change) ⇒ Boolean

Should be called when trying to remove a ‘component` who’s expected to have a hash equal to ‘change` but they are not equal. Returns `true` if `component` should be removed anyway, `false` otherwise.

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
109
# File 'lib/kintsugi/conflict_resolver.rb', line 100

def remove_component_when_unexpected_hash?(component, change)
  resolve_merge_error(
    "Trying to remove a component named '#{component.display_name}': Expected hash of " \
    "#{change} but its hash is #{component.to_tree_hash}",
    {
      'Remove object anyway': true,
      'Keep object': false
    }
  )
end

.remove_entries_when_unexpected_values_in_hash?(hash_name, expected_values, actual_values) ⇒ Boolean

Should be called when trying to remove entries from a hash of an attribute named ‘hash_name`. The values of those entries were expected to be `expected_values` but instead they are `actual_values`. Returns `true` if the entries should be removed anyway, `false` to keep the entries.

Returns:

  • (Boolean)


70
71
72
73
74
75
76
77
78
79
# File 'lib/kintsugi/conflict_resolver.rb', line 70

def remove_entries_when_unexpected_values_in_hash?(hash_name, expected_values, actual_values)
  resolve_merge_error(
    "Trying to remove entries from hash of attribute named '#{hash_name}': Expected values " \
    "for keys to be '#{expected_values}' but the existing values are '#{actual_values}'",
    {
      'Remove entries anyway': true,
      'Keep entries': false
    }
  )
end

.set_value_to_string_when_unxpected_value?(string_name, new_value, expected_value, actual_value) ⇒ Boolean

Should be called when setting a string named ‘string_name` to value `new_value` and its expected value is `expected_value` but it has a value of `actual_value`. Returns `true` if the string should be set to `new_value`, `false` if the `actual_value` should remain.

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/kintsugi/conflict_resolver.rb', line 84

def set_value_to_string_when_unxpected_value?(
  string_name, new_value, expected_value, actual_value
)
  resolve_merge_error(
    "Trying to change value of attribute named '#{string_name} from '#{new_value}' to " \
    "'#{expected_value || "nil"}', but the existing value is '#{actual_value}'",
    {
      "Set to new value '#{new_value}'": true,
      "Keep existing value '#{actual_value}'": false
    }
  )
end