Sha256: 1adb3b581946595e57611a8c535583f54b1699581aa247f6d0d21423ab6e16f2

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# coding: utf-8
# frozen_string_literal: true

module MicroRb
  class Configuration
    include Singleton

    # Sidecar settings
    attr_accessor :sidecar_registry, :sidecar_host, :sidecar_port

    # API gateway settings
    attr_accessor :gateway_host, :gateway_port, :gateway_rpc

    def self.configure
      yield(instance) if block_given?
    end

    def sidecar_uri
      "#{sidecar_host}:#{sidecar_port}"
    end

    def sidecar_registry_uri
      "#{sidecar_uri}#{sidecar_registry}"
    end

    def gateway_uri
      "#{gateway_host}:#{gateway_port}"
    end

    def gateway_rpc_uri
      "#{gateway_uri}#{gateway_rpc}"
    end

    private

    def initialize
      yield(self) if block_given?

      # Default sidecar settings
      self.sidecar_host     ||= 'http://127.0.0.1'
      self.sidecar_registry ||= '/registry'
      self.sidecar_port     ||= '8081'

      # Default API gateway settings
      self.gateway_host ||= 'http://127.0.0.1'
      self.gateway_rpc  ||= '/rpc'
      self.gateway_port ||= '3002'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
micro-rb-0.1.0.rc2 lib/micro/configuration.rb