Class: RhoDevelopment::AutoUpdater

Inherits:
Object
  • Object
show all
Defined in:
lib/build/development/auto_updater.rb

Instance Method Summary collapse

Constructor Details

#initializeAutoUpdater

Returns a new instance of AutoUpdater.



5
6
7
# File 'lib/build/development/auto_updater.rb', line 5

def initialize
  @listeners = []
end

Instance Method Details

#add_directory(string) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/build/development/auto_updater.rb', line 23

def add_directory(string)
  listener = Listen.to(string, {:debug => true}) { | modified, added, removed |
    puts 'Files were changed...'.primary
    puts "Files were added: #{added}".info
    puts "Files were modified: #{modified}".info
    puts "Files were removed: #{removed}".info
  exclude_items = (Jake.getBuildProp2('rhobundle', 'exclude_items') || []).collect { |each| %r{#{each}} }
  added_files = added.reject { |each| (exclude_items.any? { |each_item| each.index(each_item) }) }
  modified_files = modified.reject { |each| (exclude_items.any? { |each_item| each.index(each_item) }) }
  removed_files = removed.reject { |each| (exclude_items.any? { |each_item| each.index(each_item) }) }

  if ((added_files + modified_files +removed_files).empty?)
    puts 'Changes in file system were skipped because they were rejected by rules described at build.yml > rhobundle > exclude_items'.warning
  else
    self.on_file_changed(added_files, modified_files, removed_files)
  end
  }
  @listeners << listener
end

#create_diff_files(added_files, changed_files, removed_files) ⇒ Object



60
61
62
63
# File 'lib/build/development/auto_updater.rb', line 60

def create_diff_files(added_files, changed_files, removed_files)
  self.write_list_of_updated_files(added_files, changed_files)
  self.write_list_of_removed_files(removed_files)
end

#has_active_listenersObject



19
20
21
# File 'lib/build/development/auto_updater.rb', line 19

def has_active_listeners
  @listeners.any? { |each| each.processing? }
end

#on_file_changed(added_files, changed_files, removed_files) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/build/development/auto_updater.rb', line 43

def on_file_changed(added_files, changed_files, removed_files)
  puts 'The following files will be included in update bundle:'.primary
  puts "As added: #{added_files}".info
  puts "As modified: #{changed_files}".info
  puts "As removed: #{removed_files}".info
  begin
    self.create_diff_files(added_files, changed_files, removed_files)
    filename = RhoDevelopment::Configuration::next_filename_for_downloading()
    WebServer::dispatch_task(AllPlatformsPartialBundleBuildingTask.new(filename))
    WebServer::dispatch_task(AllSubscribersPartialUpdateNotifyingTask.new(filename))
  rescue => e
    puts 'Exception...'.warning
    puts e.inspect.warning
    puts e.backtrace.to_s.warning
  end
end

#relative_path(string) ⇒ Object



81
82
83
84
85
# File 'lib/build/development/auto_updater.rb', line 81

def relative_path(string)
  first = Pathname Configuration::application_root
  second = Pathname string
  second.relative_path_from first
end

#runObject



9
10
11
12
13
14
15
16
17
# File 'lib/build/development/auto_updater.rb', line 9

def run
  @listeners.each { |each|
    each.start }
  WebServer::set_auto_update_pid(Process.pid)
  puts 'Live update auto process started'.primary
  begin
    sleep 1
  end while self.has_active_listeners
end

#write_array_to_file(filename, array) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/build/development/auto_updater.rb', line 73

def write_array_to_file(filename, array)
  path = File.join(Configuration::application_root, filename)
  File.open(path, 'w') { |file|
    array.each { |each| file.puts(self.relative_path(each)) }
    file.puts '--'
  }
end

#write_list_of_removed_files(removed_files) ⇒ Object



69
70
71
# File 'lib/build/development/auto_updater.rb', line 69

def write_list_of_removed_files(removed_files)
  self.write_array_to_file('upgrade_package_remove_files.txt', removed_files)
end

#write_list_of_updated_files(added_files, changed_files) ⇒ Object



65
66
67
# File 'lib/build/development/auto_updater.rb', line 65

def write_list_of_updated_files(added_files, changed_files)
  self.write_array_to_file('upgrade_package_add_files.txt', added_files + changed_files)
end