mirror of
https://github.com/meineerde/rackstash.git
synced 2025-12-19 15:01:12 +00:00
Improve documentation for Sink#default_* accessors
This commit is contained in:
parent
c53d85fac5
commit
1b81e763b2
@ -9,17 +9,8 @@ require 'rackstash/flows'
|
|||||||
|
|
||||||
module Rackstash
|
module Rackstash
|
||||||
class Sink
|
class Sink
|
||||||
# @return [Hash, Proc] the default fields which get merged into each buffer
|
# @return [Flows] the defined {Flows} which are responsible for
|
||||||
# on {#write}.
|
# transforming, encoding, and persisting an event Hash.
|
||||||
attr_reader :default_fields
|
|
||||||
|
|
||||||
# @return [Array<#to_s, Proc>, Proc] the default tags which get merged into
|
|
||||||
# each buffer on flush. It can either be a Array of String keys or a Proc
|
|
||||||
# which returns an Array. Each element of the array can also be a Proc
|
|
||||||
# which gets resolved on {#write}.
|
|
||||||
attr_reader :default_tags
|
|
||||||
|
|
||||||
# @return [Flows] The {Flows} defined for this sink
|
|
||||||
attr_reader :flows
|
attr_reader :flows
|
||||||
|
|
||||||
# @param flows [Array<Flow, Object>, Flow, Adapters::Adapter, Object]
|
# @param flows [Array<Flow, Object>, Flow, Adapters::Adapter, Object]
|
||||||
@ -32,31 +23,30 @@ module Rackstash
|
|||||||
@default_tags = []
|
@default_tags = []
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the default fields to the given value.
|
# @return [Hash, Proc] the default fields which get deep merged into the
|
||||||
|
# created event Hash when flushing a {Buffer}.
|
||||||
|
def default_fields
|
||||||
|
@default_fields
|
||||||
|
end
|
||||||
|
|
||||||
|
# The default fields get deep merged into the created event hash when
|
||||||
|
# flushing a {Buffer}. They can be given either as a `Hash` or a `Proc`
|
||||||
|
# which in turn returns a `Hash` on `call`. The `Hash` can be nested
|
||||||
|
# arbitrarily deep.
|
||||||
#
|
#
|
||||||
# These fields get merged into each buffer on {#write}. It can either be a
|
# Each Hash value can again optionally be a Proc which in turn is expected
|
||||||
# `Hash` or a `Proc` which in turn returns a `Hash` on call. The `Hash` can
|
# to return a field value on `call`. You can set nested Hashes or Arrays and
|
||||||
# be nested arbitrarily deep.
|
# define nested Procs which in turn are called recursively when flushing a
|
||||||
#
|
# {Buffer}. That way, you can set lazy-evaluated values.
|
||||||
# Each value can also be an Proc which gets evaluated on {#write}. That way,
|
|
||||||
# you can set lazy-evaluated values.
|
|
||||||
#
|
|
||||||
# @example The following calls show equivalent results
|
|
||||||
#
|
#
|
||||||
|
# @example
|
||||||
|
# # All three values set the same default fields
|
||||||
# sink.default_fields = {'beep' => 'boop'}
|
# sink.default_fields = {'beep' => 'boop'}
|
||||||
|
# sink.default_fields = -> { { 'beep' => 'boop' } }
|
||||||
|
# sink.default_fields = { 'beep' => -> { 'boop' } }
|
||||||
#
|
#
|
||||||
# sink.default_fields = lambda {
|
# @param fields [#to_hash, Proc] The default fields to be merged into the
|
||||||
# {
|
# event Hash when flushing a {Buffer}.
|
||||||
# 'beep' => 'boop'
|
|
||||||
# }
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# sink.default_fields = {
|
|
||||||
# 'beep' => -> { 'boop' }
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# @param fields [#to_hash, Proc] The default fields to be merged into each
|
|
||||||
# buffer on {#write}
|
|
||||||
# @raise [TypeError] if `fields` is neither a Proc nor can be converted to a
|
# @raise [TypeError] if `fields` is neither a Proc nor can be converted to a
|
||||||
# Hash
|
# Hash
|
||||||
# @return [Hash, Proc] the given `fields`
|
# @return [Hash, Proc] the given `fields`
|
||||||
@ -69,28 +59,32 @@ module Rackstash
|
|||||||
@default_fields = fields
|
@default_fields = fields
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the default tags to the given value.
|
# @return [Array<#to_s, Proc>, Proc] the default tags are added to the
|
||||||
|
# `"@tags"` field of the created event Hash when flushing a {Buffer}. They
|
||||||
|
# can be given either as an `Array` of `String`s or a `Proc` which in turn
|
||||||
|
# returns an `Array` of `String`s on `call`.
|
||||||
|
def default_tags
|
||||||
|
@default_tags
|
||||||
|
end
|
||||||
|
|
||||||
|
# The default tags are added to the `"@tags"` field of the created event
|
||||||
|
# Hash when flushing a {Buffer}. They can be given either as an `Array` of
|
||||||
|
# `String`s or a `Proc` which in turn returns an `Array` of `String`s on
|
||||||
|
# `call`.
|
||||||
#
|
#
|
||||||
# These tags get merged into each buffer on {#write}. It can either be an
|
# Each value of the Array can again optionally be a Proc which in turn is
|
||||||
# `Array` of strings or a `Proc` which in turn returns an `Array` of strings
|
# expected to return a String on `call`. All the (potentially nested) procs
|
||||||
# on call. The array's values can also be procs which should return a String
|
# are called recursively when flushing a {Buffer}. That way, you can set
|
||||||
# on call. All procs are evaluated on {#write}. That way, you can set
|
|
||||||
# lazy-evaluated values.
|
# lazy-evaluated values.
|
||||||
#
|
#
|
||||||
# @example The following calls show equivalent results
|
# @example
|
||||||
#
|
# # All three values set the same default tags
|
||||||
# sink.default_tags = ['important', 'request']
|
# sink.default_tags = ['important', 'request']
|
||||||
|
# sink.default_tags = -> { ['important', 'request'] }
|
||||||
|
# sink.default_tags = [ 'important', -> { 'request' } }
|
||||||
#
|
#
|
||||||
# sink.default_tags = lambda {
|
# @param tags [#to_ary, Proc] The default tags to be merged into the event
|
||||||
# ['important', 'request']
|
# Hash's `"@tags"` field when flushing a {Buffer}
|
||||||
# }
|
|
||||||
#
|
|
||||||
# sink.default_tags = [
|
|
||||||
# 'important', -> { 'request' }
|
|
||||||
# }
|
|
||||||
#
|
|
||||||
# @param tags [#to_ary, Proc] The default tags to be merged into each
|
|
||||||
# buffer on {#write}
|
|
||||||
# @raise [TypeError] if `tags` is neither a Proc nor can be converted to an
|
# @raise [TypeError] if `tags` is neither a Proc nor can be converted to an
|
||||||
# Array
|
# Array
|
||||||
# @return [Array, Proc] the given `tags`
|
# @return [Array, Proc] the given `tags`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user