Module: Hanami::Port Private

Defined in:
lib/hanami/port.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.1

Constant Summary collapse

DEFAULT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.1

2300
ENV_VAR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.1

"HANAMI_PORT"

Class Method Summary collapse

Class Method Details

.call(value, env = ENV.fetch(ENV_VAR, nil)) ⇒ Object Also known as: []

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.1



17
18
19
20
21
22
23
# File 'lib/hanami/port.rb', line 17

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

.call!(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.1



27
28
29
30
31
# File 'lib/hanami/port.rb', line 27

def self.call!(value)
  return if default?(value)

  ENV[ENV_VAR] = value.to_s
end

.default?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 2.0.1



35
36
37
# File 'lib/hanami/port.rb', line 35

def self.default?(value)
  value.to_i == DEFAULT
end