class MagicPipe::Config

Constants

FIELDS

Public Class Methods

new() { |self| ... } click to toggle source
# File lib/magic_pipe/config.rb, line 27
def initialize
  yield self if block_given?
  set_defaults
end

Private Instance Methods

dummy_metrics_object() click to toggle source
# File lib/magic_pipe/config.rb, line 106
def dummy_metrics_object
  Class.new do
    def initialize(logger)
      @out = logger
    end
    def method_missing(name, *args, &block)
      @out.debug("[metrics] #{name}: #{args}")
      # Uncomment this to create a black hole
      # self.class.new(@out)
    end
    def respond_to_missing?(*)
      true
    end
  end.new(@logger)
end
method_missing(name, *args, &block) click to toggle source
# File lib/magic_pipe/config.rb, line 111
def method_missing(name, *args, &block)
  @out.debug("[metrics] #{name}: #{args}")
  # Uncomment this to create a black hole
  # self.class.new(@out)
end
respond_to_missing?(*) click to toggle source
# File lib/magic_pipe/config.rb, line 116
def respond_to_missing?(*)
  true
end
set_async_defaults() click to toggle source

Since Sidekiq is the go-to sender for production, this should always be defined.

# File lib/magic_pipe/config.rb, line 97
def set_async_defaults
  @async_transport_options ||= {}
  defaults = {
    queue: "magic_pipe"
  }
  @async_transport_options = defaults.merge(@async_transport_options)
end
set_defaults() click to toggle source
# File lib/magic_pipe/config.rb, line 36
def set_defaults
  @client_name ||= "magic_pipe"
  @producer_name ||= "Anonymous Piper"
  @logger ||= Logger.new($stdout)
  @metrics_client ||= dummy_metrics_object

  @loader ||= :simple_active_record
  @sender ||= :sync
  @codec ||= :yaml
  @transport ||= :log

  set_https_defaults
  set_sqs_defaults
  set_async_defaults
end
set_https_defaults() click to toggle source
# File lib/magic_pipe/config.rb, line 53
def set_https_defaults
  return unless @https_transport_options

  defaults = {
    # The base URL. It can contain a path
    #
    url: "https://localhost:8080/foo",
    #
    # A callable that receives the topic name.
    # For example if you want to use the topic
    # as sub path, provide an identity proc:
    #
    #  -> (t) { t }
    #
    # The callable should return an absolute "/my/path"
    # value to replace the entire path of the configured
    # URL. It should return a relative "my/path" value
    # to simply append the dynamic path to the base URL.
    #
    # When this parameter is nil, the configured URL
    # will be used as is.
    #
    dynamic_path_builder: nil,

    basic_auth: "missing:x",
    timeout: 2,
    open_timeout: 3,
  }
  @https_transport_options = defaults.merge(@https_transport_options)
end
set_sqs_defaults() click to toggle source
# File lib/magic_pipe/config.rb, line 85
def set_sqs_defaults
  @sqs_transport_options ||= {}
  defaults = {
    queue: "magic_pipe",
  }
  @sqs_transport_options = defaults.merge(@sqs_transport_options)
end