Class: CloudRCS::PrimitivePatch
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CloudRCS::PrimitivePatch
show all
- Defined in:
- lib/cloud_rcs/primitive_patch.rb
Overview
PrimitivePatch acts as an intermediary between Patch and the primitive patch types. It allows primitive patches to inherit methods from Patch, and to use the same table. But it also allows for defining behavior that differs from Patch but that is automatically inherited by all primitive patch types.
Constant Summary
collapse
- PATH_PREFIX =
"./"
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.escape_path(path) ⇒ Object
Replace special charecters in file paths with ASCII codes bounded by backslashes.
121
122
123
124
125
126
127
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 121
def escape_path(path)
special_chars = ['\\\\',' ']
path.gsub(/#{special_chars.join('|')}/) { |match| "\\#{match[0]}\\" }
end
|
.generate(orig_file, changed_file) ⇒ Object
101
102
103
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 101
def generate(orig_file, changed_file)
override "generate"
end
|
.merge(patch_a, patch_b) ⇒ Object
109
110
111
112
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 109
def merge(patch_a, patch_b)
patch_b_prime = commute(patch_a.inverse, patch_b).first
return patch_a, patch_b_prime
end
|
.parse(contents) ⇒ Object
105
106
107
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 105
def parse(contents)
override "parse"
end
|
.priority ⇒ Object
Patch type priority represents the relative likelihood that a patch type will cause conflicts if it is applied before other patch types. Patch types with a high priority value are likely to cause conflicts if they are applied early, and so should be deferred until after other patch types have done their thing.
Default priority is 50.
97
98
99
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 97
def priority
return 50
end
|
.unescape_path(path) ⇒ Object
Replace escaped characters with the original versions. Escaped characters are of the format, /\(d2,3)\/; where the digits enclosed in backslashes represent the ASCII code of the original character.
133
134
135
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 133
def unescape_path(path)
path.gsub(/\\(\d{2,3})\\/) { $1.to_i.chr }
end
|
Instance Method Details
#apply! ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 23
def apply!
target_file = locate_file(original_path || path)
old_target = target_file
target_file = apply_to(target_file)
if target_file.nil?
old_target.destroy
else
target_file.save
end
return target_file
end
|
#apply_to(file) ⇒ Object
def locate_file(path)
raise "You must override the locate_file method for PrimitivePatch."
self.class.file_class.locate(path)
end
44
45
46
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 44
def apply_to(file)
override "apply_to(file)"
end
|
#commute(patch) ⇒ Object
52
53
54
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 52
def commute(patch)
override "commute(patch)"
end
|
#inverse ⇒ Object
48
49
50
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 48
def inverse
override "inverse"
end
|
#named_patch? ⇒ Boolean
36
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 36
def named_patch?; false; end
|
#new_path ⇒ Object
64
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 64
def new_path; path; end
|
#primitive_patch? ⇒ Boolean
37
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 37
def primitive_patch?; true; end
|
#to_a ⇒ Object
60
61
62
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 60
def to_a
[self]
end
|
#to_s ⇒ Object
56
57
58
|
# File 'lib/cloud_rcs/primitive_patch.rb', line 56
def to_s
override "to_s"
end
|