Class: Controller

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cuco/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#listenerObject (readonly)

Returns the value of attribute listener.



9
10
11
# File 'lib/cuco/controller.rb', line 9

def listener
  @listener
end

Instance Method Details

#file_run(pattern, type = nil) ⇒ Object



42
43
44
45
46
# File 'lib/cuco/controller.rb', line 42

def file_run(pattern, type = nil)
  puts "*** file_run(#{pattern}, #{type})" if debug
  rules = find_rules(pattern, type)
  rules.each { |rule| match_run(rule, pattern) }
end

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/cuco/controller.rb', line 11

def run
  puts "*** Controller.run" if debug
  @listener = Listen.to(".") do |modified, added, removed|
    run_files(modified, :modified)
    run_files(added, :added)
  end

  @listener.start
  puts "*** Listen started" if debug
  # sleep # fails with Ruby 4.0.0
  sleep 24 * 60 * 60
end

#run_files(files, type) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/cuco/controller.rb', line 31

def run_files(files, type)
  puts "*** Controller.run_files(#{files}, #{type})" if debug
  if files.include?(G.scriptname)
    G.script = Script.new File.read(G.scriptname)
    return
  end

  files.map! { |filename| filename[G.pwd_length + 1..] }
  files.each { |filename| file_run(filename, type) }
end

#stopObject



24
25
26
27
28
29
# File 'lib/cuco/controller.rb', line 24

def stop
  puts "*** Controller.stop" if debug
  @listener&.stop
  G.script = nil
  @listener = nil
end