class Ocular::Daemon

Attributes

eventfactory[RW]

Public Class Methods

new(root_path) click to toggle source
# File lib/ocular/daemon.rb, line 9
def initialize(root_path)

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

Public Instance Methods

get_name_from_file(filename) click to toggle source
# 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) click to toggle source
# File lib/ocular/daemon.rb, line 15
def get_script_files(root)
    return Dir::glob("#{root}/**/*.rb")
end
load_script_files() click to toggle source
# 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_handlers() click to toggle source
# File lib/ocular/daemon.rb, line 39
def start_input_handlers()
    @eventfactory.start_input_handlers()
end
stop_input_handlers() click to toggle source
# File lib/ocular/daemon.rb, line 43
def stop_input_handlers()
    @eventfactory.stop_input_handlers()
end
wait() click to toggle source
# 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