Class: Ocular::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/ocular/daemon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path) ⇒ Daemon

Returns a new instance of Daemon.



9
10
11
12
13
# File 'lib/ocular/daemon.rb', line 9

def initialize(root_path)

    @root_path = root_path
    @eventfactory = ::Ocular::Event::EventFactory.new
end

Instance Attribute Details

#eventfactoryObject

Returns the value of attribute eventfactory.



7
8
9
# File 'lib/ocular/daemon.rb', line 7

def eventfactory
  @eventfactory
end

Instance Method Details

#get_name_from_file(filename) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ocular/daemon.rb', line 19

def get_name_from_file(filename)

    # -4 will strip the ".rb" away from the end
    name = filename[@root_path.length..-4]

    # If root_path is empty then we need to strip the '/' from the beginning
    if name[0] == '/'
        name = name[1..-1]
    end

    return name
end

#get_script_files(root) ⇒ Object



15
16
17
# File 'lib/ocular/daemon.rb', line 15

def get_script_files(root)
    return Dir::glob("#{root}/**/*.rb")
end

#load_script_filesObject



32
33
34
35
36
37
# File 'lib/ocular/daemon.rb', line 32

def load_script_files()
    files = self.get_script_files(@root_path)
    for file in files
        @eventfactory.load_from_file(file, get_name_from_file(file))
    end
end

#start_input_handlersObject



39
40
41
# File 'lib/ocular/daemon.rb', line 39

def start_input_handlers()
    @eventfactory.start_input_handlers()
end

#stop_input_handlersObject



43
44
45
# File 'lib/ocular/daemon.rb', line 43

def stop_input_handlers()
    @eventfactory.stop_input_handlers()
end

#waitObject



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ocular/daemon.rb', line 47

def wait()
    while true
        begin
            sleep 60
        rescue Interrupt
            stop_input_handlers()
            puts "\nGoing to exit"
            return
        end
    end
end