Class: Fusuma::Runner
- Inherits:
-
Object
- Object
- Fusuma::Runner
- Defined in:
- lib/fusuma.rb
Overview
main class
Class Method Summary collapse
Instance Method Summary collapse
- #buffer(event) ⇒ Object
- #detect(buffers) ⇒ Array<Event>
- #execute(event) ⇒ Object
- #filter(event) ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #merge(events) ⇒ Event, NilClass
- #parse(event) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
78 79 80 81 82 83 84 85 |
# File 'lib/fusuma.rb', line 78 def initialize @inputs = Plugin::Inputs::Input.plugins.map(&:new) @filters = Plugin::Filters::Filter.plugins.map(&:new) @parsers = Plugin::Parsers::Parser.plugins.map(&:new) @buffers = Plugin::Buffers::Buffer.plugins.map(&:new) @detectors = Plugin::Detectors::Detector.plugins.map(&:new) @executors = Plugin::Executors::Executor.plugins.map(&:new) end |
Class Method Details
.run(option = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/fusuma.rb', line 14 def run(option = {}) set_trap (option) instance = new instance.run end |
Instance Method Details
#buffer(event) ⇒ Object
107 108 109 |
# File 'lib/fusuma.rb', line 107 def buffer(event) @buffers.each { |b| b.buffer(event) } end |
#detect(buffers) ⇒ Array<Event>
113 114 115 116 117 118 119 120 121 |
# File 'lib/fusuma.rb', line 113 def detect(buffers) @detectors.reduce([]) do |detected, detector| if (event = detector.detect(buffers)) detected << event else detected end end end |
#execute(event) ⇒ Object
137 138 139 140 141 142 143 144 145 |
# File 'lib/fusuma.rb', line 137 def execute(event) return unless event executor = @executors.find do |e| e.executable?(event) end executor&.execute(event) end |
#filter(event) ⇒ Object
99 100 101 |
# File 'lib/fusuma.rb', line 99 def filter(event) event if @filters.any? { |f| f.filter(event) } end |
#merge(events) ⇒ Event, NilClass
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/fusuma.rb', line 126 def merge(events) main_events, modifiers = events.partition { |event| event.record.mergable? } return nil unless (main_event = main_events.first) # NOTE: clear buffers after detected main_event @buffers.each(&:clear) main_event.record.merge(records: modifiers.map(&:record)) main_event end |
#parse(event) ⇒ Object
103 104 105 |
# File 'lib/fusuma.rb', line 103 def parse(event) @parsers.reduce(event) { |e, p| p.parse(e) if e } end |
#run ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fusuma.rb', line 87 def run # TODO: run with multi thread @inputs.first.run do |event| filtered = filter(event) parsed = parse(filtered) buffered = buffer(parsed) detected = detect(buffered) merged = merge(detected) execute(merged) end end |