Skip to content

Commit 59e93c3

Browse files
committed
Doc examples use new Context#add_output
1 parent ae60632 commit 59e93c3

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,15 @@ like `to_field`, is executed for every record, but without being tied
311311
to a specific output field.
312312

313313
`each_record` can be used for logging or notifiying, computing intermediate
314-
results, or writing to more than one field at once.
314+
results, or more complex ruby logic.
315315

316316
~~~ruby
317317
each_record do |record|
318318
some_custom_logging(record)
319319
end
320+
each_record do |record, context|
321+
context.add_output(:some_value, extract_some_value_from_record(record))
322+
end
320323
~~~
321324

322325
For more on `each_record`, see [Indexing Rules: Macros and Custom Logic](./doc/indexing_rules.md).

doc/indexing_rules.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,12 @@ each_record do |record, context|
247247
end
248248

249249
each_record do |record, context|
250-
(val1, val2) = calculate_two_things_from(record)
250+
if eligible_for_things?(record)
251+
(val1, val2) = calculate_two_things_from(record)
251252

252-
context.output_hash["first_field"] ||= []
253-
context.output_hash["first_field"] << val1
254-
255-
context.output_hash["second_field"] ||= []
256-
context.output_hash["second_field"] << val2
253+
context.add_output("first_field", val1)
254+
context.add_output("second_field", val2)
255+
end
257256
end
258257
~~~
259258

0 commit comments

Comments
 (0)