Class: Sicily::MonitorWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/sicily/monitor_wrapper.rb

Class Method Summary collapse

Class Method Details

.can_monitor?(prev_paths, new_path) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
# File 'lib/sicily/monitor_wrapper.rb', line 30

def self.can_monitor?(prev_paths, new_path)
  prev_paths.each do |prev_path|
    return false if somehow_related?(prev_path, new_path)
  end

  true
end

.on(path, &user_rule_block) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/sicily/monitor_wrapper.rb', line 7

def self.on(path, &user_rule_block)
  if can_monitor?(@monitored_paths, path)
    store_path_and_start_monitor(path, &user_rule_block)
  else
    Sicily.logger.error "Monitor Failed. Path duplicated : #{path}"
  end
end

.somehow_related?(path1, path2) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/sicily/monitor_wrapper.rb', line 38

def self.somehow_related?(path1, path2)
  parent_child_relationship = Util::FileUtil.related?(path1, path2)
  child_parent_relationship = Util::FileUtil.related?(path2, path1)

  parent_child_relationship || child_parent_relationship
end

.start_monitor!(path, &user_rule_block) ⇒ Object



20
21
22
23
24
# File 'lib/sicily/monitor_wrapper.rb', line 20

def self.start_monitor!(path, &user_rule_block)
  Monitor.new.on(path, &user_rule_block)
rescue MonitorError => e
  Sicily.logger.error e.inspect
end

.store_monitored_path(path) ⇒ Object



26
27
28
# File 'lib/sicily/monitor_wrapper.rb', line 26

def self.store_monitored_path(path)
  @monitored_paths << File.expand_path(path)
end

.store_path_and_start_monitor(path, &user_rule_block) ⇒ Object



15
16
17
18
# File 'lib/sicily/monitor_wrapper.rb', line 15

def self.store_path_and_start_monitor(path, &user_rule_block)
  store_monitored_path(path)
  start_monitor!(path, &user_rule_block)
end