Sha256: e1cd40991015771465e04adb7e18ee9d7dbb550ecb1ddc56ab833b135e9b2827

Contents?: true

Size: 837 Bytes

Versions: 15

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

module Hanami
  # @since 2.0.1
  # @api private
  module Port
    # @since 2.0.1
    # @api private
    DEFAULT = 2300

    # @since 2.0.1
    # @api private
    ENV_VAR = "HANAMI_PORT"

    # @since 2.0.1
    # @api private
    def self.call(value, env = ENV.fetch(ENV_VAR, nil))
      return Integer(value) if !value.nil? && !default?(value)
      return Integer(env) unless env.nil?
      return Integer(value) unless value.nil?

      DEFAULT
    end

    # @since 2.0.1
    # @api private
    def self.call!(value)
      return if default?(value)

      ENV[ENV_VAR] = value.to_s
    end

    # @since 2.0.1
    # @api private
    def self.default?(value)
      value.to_i == DEFAULT
    end

    class << self
      # @since 2.0.1
      # @api private
      alias_method :[], :call
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
hanami-2.2.1 lib/hanami/port.rb
hanami-2.2.0 lib/hanami/port.rb
hanami-2.2.0.rc1 lib/hanami/port.rb
hanami-2.2.0.beta2 lib/hanami/port.rb
hanami-2.2.0.beta1 lib/hanami/port.rb
hanami-2.1.0 lib/hanami/port.rb
hanami-2.1.0.rc3 lib/hanami/port.rb
hanami-2.1.0.rc2 lib/hanami/port.rb
hanami-2.1.0.rc1 lib/hanami/port.rb
hanami-2.1.0.beta2.1 lib/hanami/port.rb
hanami-2.1.0.beta2 lib/hanami/port.rb
hanami-2.1.0.beta1 lib/hanami/port.rb
hanami-2.0.3 lib/hanami/port.rb
hanami-2.0.2 lib/hanami/port.rb
hanami-2.0.1 lib/hanami/port.rb