Class: AlsDelta
- Inherits:
-
Object
show all
- Includes:
- Run
- Defined in:
- lib/als_delta/als_delta_class.rb
Instance Method Summary
collapse
Methods included from Run
#run, #run_capture_stdout
Constructor Details
#initialize(set_name, **options) ⇒ AlsDelta
Returns a new instance of AlsDelta.
10
11
12
13
14
15
16
17
18
|
# File 'lib/als_delta/als_delta_class.rb', line 10
def initialize(set_name, **options)
@options = options
@loglevel = "-loglevel #{@options[:loglevel]}"
@loglevel += ' -stats' unless @options[:loglevel] == 'quiet'
@set_name = set_name
@set_dir = File.dirname set_name
@set_name_only = File.basename set_name, '.als'
end
|
Instance Method Details
#backup_name ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/als_delta/als_delta_class.rb', line 20
def backup_name
@backup_name = if @options[:keep]
timestamp = Time.now.getutc.strftime '%Y-%m-%d_%H:%M:%S'
"#{@set_dir}/#{@set_name_only}_#{timestamp}.als"
else
"#{@set_dir}/#{@set_name_only}_backup.als"
end
end
|
#backup_set ⇒ Object
29
30
31
32
33
|
# File 'lib/als_delta/als_delta_class.rb', line 29
def backup_set
@backup_name = backup_name
puts "Backing up Live set to '#{@backup_name}'"
FileUtils.cp @set_name, @backup_name
end
|
#cleanup ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/als_delta/als_delta_class.rb', line 35
def cleanup
return if @options[:keep] || !@backup_name
return unless File.exist? @backup_name
puts "Deleting '#{@backup_name}'"
File.delete @backup_name
end
|
#show ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/als_delta/als_delta_class.rb', line 43
def show
backup_set
loop do
puts 'Press any key to display the changes to the Live set XML file, or press Esc to exit.'
character = $stdin.getch
exit if character.ord == 27
output = run_capture_stdout "GZIP=--no-name zdiff #{@set_name.shellescape} #{@backup_name.shellescape}"
if output.empty?
puts 'There were no changes to the saved live set.'
else
puts output.join("\n")
backup_set
end
rescue StandardError => e
puts e
end
end
|