Class: Langis::Dsl::IntakeConfig

Inherits:
Object
  • Object
show all
Includes:
Blockenspiel::DSL
Defined in:
lib/langis/dsl.rb

Overview

Dsl config class used to define an intake.

See Also:

  • #langis_plumbing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIntakeConfig

Returns a new instance of IntakeConfig.



224
225
226
# File 'lib/langis/dsl.rb', line 224

def initialize
  @sink_type_links = {}
end

Instance Attribute Details

Returns the intake’s configuration mapping between its sinks (names) and the list of types to filter for.

Returns:

  • (Hash{String => Set<String>})

    The sink name to the set of message types to filter for.



220
221
222
# File 'lib/langis/dsl.rb', line 220

def sink_type_links
  @sink_type_links
end

Instance Method Details

#flow_to(...) ⇒ Object #flow_to(..., options = {}) ⇒ Object

Dsl only method to define which sinks to propagate a message to.

Overloads:

  • #flow_to(...) ⇒ Object

    Flow all messages for the intake to the given sink names.

    Parameters:

    • ... (Array<#to_s>)

      The list of sink names to push messages to.

  • #flow_to(..., options = {}) ⇒ Object

    Flow all messages for the intake to the given sink names, but

    may be restricted by type if that option is set.
    

    Parameters:

    • ... (Array<#to_s>)

      The list of sink names to push messages to.

    Options Hash (options):

    • :when (Array<#to_s>) — default: []

      The list of message types that should be sent to the sink, all unlisted types are filtered out. If a sink has zero listed types at the end of the Dsl config, then ALL messages will be sent to that sink.



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/langis/dsl.rb', line 244

def flow_to(*args)
  # Check to see if we have an options hash. Properly pull out the
  # options, and then make the list of sinks to push to.
  case args[-1]
  when Hash
    options = args[-1]
    sink_names = args[0...-1].map! { |name| name.to_s }
  else
    options = {}
    sink_names = args.clone.map! { |name| name.to_s }
  end

  # Coerce the message types to handle into an Array of strings
  case options[:when]
  when Array
    message_types = options[:when].map { |item| item.to_s }
  when nil
    # For the nil case, we have an empty array.
    # The build_pipes method will interpret a sink with an empty set
    # of types to actually handle all types.
    message_types = []
  else
    message_types = [ options[:when].to_s ]
  end

  # We add the types to a Set, one set per sink name. This is for the
  # multiple intake definitions.
  sink_names.each do |name|
    @sink_type_links[name] ||= Set.new
    @sink_type_links[name].merge message_types
  end
end