Class: Carnivore::Source::SourceContainer

Inherits:
Object
  • Object
show all
Defined in:
lib/carnivore/source_container.rb

Overview

Container for holding source configuration. This allows setup to occur prior to the supervisor actually starting the sources

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (SourceContainer) initialize(class_name, args = {})

Create a new source container

Parameters:

  • class_name (Class)

    class of Source

  • args (Hash) (defaults to: {})

    configuration hash for source



19
20
21
22
23
# File 'lib/carnivore/source_container.rb', line 19

def initialize(class_name, args={})
  @klass = class_name
  @source_hash = Smash.new(args || {})
  @source_hash[:callbacks] = Smash.new
end

Instance Attribute Details

- (Class) klass (readonly)

Returns class of Source

Returns:

  • (Class)

    class of Source



11
12
13
# File 'lib/carnivore/source_container.rb', line 11

def klass
  @klass
end

- (Hash) source_hash (readonly)

Returns configuration hash for Source

Returns:

  • (Hash)

    configuration hash for Source



13
14
15
# File 'lib/carnivore/source_container.rb', line 13

def source_hash
  @source_hash
end

Instance Method Details

- (Class, Proc) add_callback(name, klass = nil) {|message| ... }

name

Name of callback

klass

Class of callback (optional)

Add a callback to a source via Class or block

Parameters:

  • name (String, Symbol)

    name of callback

  • klass (Class) (defaults to: nil)

    class of callback

Yields:

  • callback block

Yield Parameters:

Returns:

  • (Class, Proc)

    callback registered



34
35
36
# File 'lib/carnivore/source_container.rb', line 34

def add_callback(name, klass=nil, &block)
  @source_hash[:callbacks][name] = klass || block
end