Sha256: 85685a42d08b2749468df1a786d29338651bee96ce453d8382388dd0bc2ac070

Contents?: true

Size: 963 Bytes

Versions: 2

Compression:

Stored size: 963 Bytes

Contents

require 'socket'

module StackAgent
  class Configuration
    DEFAULT_API_HOST = 'https://stackotron-discover.herokuapp.com'

    attr_accessor :api_host
    attr_accessor :app_token
    attr_accessor :name
    attr_accessor :group
    attr_accessor :uri

    def initialize
      @api_host = DEFAULT_API_HOST
      @name = Socket.gethostname

      # If we're running inside rails, attempt to fill in a bunch of the blanks
      if defined?(Rails) && Rails.env.development?
        @group = 'Development'
        @uri = "http://#{ip}:#{port}" if port
      end
    end

    private

    def ip
      Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
    end

    def port
      return Rails::Server.new.options[:Port] if defined?(Rails::Server)
      return ENV['PORT'] if (ENV['PORT'] && is_known_http_server?)
    end

    def is_known_http_server?
      %w(puma unicorn thin rackup).include?(File.basename($0))
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
stack-agent-0.1.3 lib/stack-agent/configuration.rb
stack-agent-0.1.2 lib/stack-agent/configuration.rb