Class: ScribeIt
- Inherits:
-
Object
- Object
- ScribeIt
- Defined in:
- lib/scribeit.rb,
lib/scribeit/log.rb,
lib/scribeit/source.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Method Summary collapse
-
#initialize(config) ⇒ ScribeIt
constructor
A new instance of ScribeIt.
- #register ⇒ Object
- #register_signal_handler ⇒ Object
- #run(&block) ⇒ Object
- #stop ⇒ Object
Constructor Details
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/scribeit.rb', line 9 def config @config end |
#sources ⇒ Object (readonly)
Returns the value of attribute sources.
10 11 12 |
# File 'lib/scribeit.rb', line 10 def sources @sources end |
Instance Method Details
#register ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/scribeit.rb', line 19 def register if !@config.has_key? "sources" raise "Config error - no sources defined" end sources = @config["sources"] sources.each do |source| puts source.inspect if source.is_a? Array or source.is_a? Hash cat, files = source else raise "Config error - no category for file: #{files.inspect}" end files = [files] if !files.is_a? Array files.each do |f| @logger.debug("Adding new source #{f} to category #{cat}") s = ScribeIt::Source.new(f, cat) { |event| fire(event) } s.register @sources << s end end register_signal_handler end |
#register_signal_handler ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/scribeit.rb', line 58 def register_signal_handler @signals = EventMachine::Channel.new Signal.trap("INT") do @signals.push(:INT) end Signal.trap("USR1") do @signals.push(:USR1) end @signals.subscribe do |msg| case msg when :USR1 #eventually, we want to reload our config. # for now, we'll just show what we're looking at. puts @sources when :INT EventMachine.stop_event_loop end end end |
#run(&block) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/scribeit.rb', line 46 def run(&block) EventMachine.epoll EventMachine.run do self.register yield if block_given? end end |
#stop ⇒ Object
54 55 56 |
# File 'lib/scribeit.rb', line 54 def stop EventMachine.stop_event_loop end |