Class: Controller

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/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/controller.rb', line 9

def listener
  @listener
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#pwd_sizeObject (readonly)

Returns the value of attribute pwd_size.



11
12
13
# File 'lib/controller.rb', line 11

def pwd_size
  @pwd_size
end

#scriptObject (readonly)

Returns the value of attribute script.



13
14
15
# File 'lib/controller.rb', line 13

def script
  @script
end

#script_nameObject (readonly)

Returns the value of attribute script_name.



12
13
14
# File 'lib/controller.rb', line 12

def script_name
  @script_name
end

Instance Method Details

#init(options, argv) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/controller.rb', line 15

def init(options, argv)
  @options = options
  @script_name = argv.first || ".watchr"
  @pwd_size = Dir.pwd.size

  if @options[:debug]
    puts "options #{@options}"
    puts "pwd     <#{@pwd}>"
    puts "script_name <#{@script_name}>"
  end
end

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/controller.rb', line 27

def run
  stop
  @script = Script.new
  @script.load_file(@script_name)
  @listener = Listen.to(".") do |modified, added, removed|
    run_files(modified, :modified)
    run_files(added, :added)
  end

  @listener.start
  sleep
end

#stopObject



40
41
42
43
44
# File 'lib/controller.rb', line 40

def stop
  @listener&.stop
  @script = nil
  @listener = nil
end