Module: Kinetic::DSL

Included in:
Base
Defined in:
lib/kinetic/dsl.rb

Instance Method Summary collapse

Instance Method Details

#get(key) ⇒ Object?

Gets a configuration value

Parameters:

  • key (Symbol)

    the key of the value to get

Returns:

  • (Object, nil)

    returns the requested configuration value or nil if the value does not exist



21
22
23
# File 'lib/kinetic/dsl.rb', line 21

def get(key)
  config[key.to_sym]
end

#get!(key) ⇒ Object

Gets a configuration value and returns an exception if the value is not present

Parameters:

  • key (Symbol)

    the key of the value to get

Returns:

  • (Object)

Raises:



32
33
34
35
# File 'lib/kinetic/dsl.rb', line 32

def get!(key)
  raise Kinetic::Errors::MissingConfigurationValue.new(key) unless (value = get(key))
  value
end

#loggerLogger

Returns the application logger instance

Returns:

  • (Logger)

    returns the application logger instance



56
57
58
# File 'lib/kinetic/dsl.rb', line 56

def logger
  @logger ||= reopen_logger
end

#on_direct(key) {|message| ... } ⇒ Object Also known as: on

Defines a direct queue subscription. Direct queues do not allow fuzzy matching so all messages sent to this queue must exactly match the key.

Parameters:

  • key (String)

    the key of the queue to which to subscribe.

Yields:

  • (message)

    yields the message passed to the queue to the block

Raises:



46
47
48
49
50
51
# File 'lib/kinetic/dsl.rb', line 46

def on_direct(key, &block)
  raise Kinetic::Errors::NoSubscriberBlock unless block_given?
  raise Kinetic::Errors::KeyMustBeString   unless key.is_a? String
  logger.debug "Setting up '#{key}' on 'direct'"
  direct[key] = block
end

#set(key, value) ⇒ Boolean

Sets a configuration value

Parameters:

  • key (Symbol)

    the configuration key to set

  • value (Symbol)

    the configuration value

Returns:

  • (Boolean)

    returns true



11
12
13
14
# File 'lib/kinetic/dsl.rb', line 11

def set(key, value)
  config[key.to_sym] = value
  true
end