Class: Sawmill::EntryProcessor::BuildRecords
- Inherits:
-
Base
- Object
- Base
- Sawmill::EntryProcessor::BuildRecords
show all
- Defined in:
- lib/sawmill/entry_processor/build_records.rb
Overview
An entry processor that builds log records from a stream of entries, and passes those log records to the given record processor.
Instance Method Summary
collapse
Methods inherited from Base
add_dsl_method, inherited
Constructor Details
#initialize(processor_, opts_ = {}) ⇒ BuildRecords
Create record builder emitting to the given record processor.
Recognized options include:
:emit_incomplete_records_on_finish
-
When the processor is finished, any records that are still not complete will be emitted to the record processor anyway, even in their incomplete state.
57
58
59
60
61
|
# File 'lib/sawmill/entry_processor/build_records.rb', line 57
def initialize(processor_, opts_={})
@processor = processor_
@records = {}
@emit_incomplete_records_on_finish = opts_[:emit_incomplete_records_on_finish]
end
|
Instance Method Details
#attribute(entry_) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/sawmill/entry_processor/build_records.rb', line 118
def attribute(entry_)
return unless @records
record_ = @records[entry_.record_id]
if record_
record_.add_entry(entry_)
true
else
@processor.(entry_)
false
end
end
|
#begin_record(entry_) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/sawmill/entry_processor/build_records.rb', line 78
def begin_record(entry_)
return unless @records
record_id_ = entry_.record_id
if @records.include?(record_id_)
@processor.(entry_)
false
else
@records[record_id_] = Record.new([entry_])
true
end
end
|
#emit_incomplete_records ⇒ Object
Emit all currently incomplete records immediately in their incomplete state. This clears those incomplete records, so note that if they do get completed later, they will not be re-emitted.
68
69
70
71
72
73
74
75
|
# File 'lib/sawmill/entry_processor/build_records.rb', line 68
def emit_incomplete_records
if @records
@records.values.each do |record_|
@processor.record(record_)
end
@records.clear
end
end
|
#end_record(entry_) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/sawmill/entry_processor/build_records.rb', line 91
def end_record(entry_)
return unless @records
record_ = @records.delete(entry_.record_id)
if record_
record_.add_entry(entry_)
@processor.record(record_)
true
else
@processor.(entry_)
false
end
end
|
#finish ⇒ Object
138
139
140
141
142
143
144
145
146
|
# File 'lib/sawmill/entry_processor/build_records.rb', line 138
def finish
if @records
emit_incomplete_records if @emit_incomplete_records_on_finish
@records = nil
@processor.finish
else
nil
end
end
|
#message(entry_) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/sawmill/entry_processor/build_records.rb', line 105
def message(entry_)
return unless @records
record_ = @records[entry_.record_id]
if record_
record_.add_entry(entry_)
true
else
@processor.(entry_)
false
end
end
|
#unknown_data(entry_) ⇒ Object
131
132
133
134
135
|
# File 'lib/sawmill/entry_processor/build_records.rb', line 131
def unknown_data(entry_)
return unless @records
@processor.(entry_)
false
end
|