Class: DhanHQ::Utils::NetworkInspector
- Inherits:
-
Object
- Object
- DhanHQ::Utils::NetworkInspector
- Defined in:
- lib/DhanHQ/utils/network_inspector.rb
Overview
Collects network and environment metadata for order audit logging.
Results are memoized at class level so that repeated calls within a single process do not incur additional HTTP round-trips to the IP-lookup services.
Constant Summary collapse
- IPV4_URI =
URI("https://api.ipify.org")
- IPV6_URI =
URI("https://api64.ipify.org")
Class Method Summary collapse
-
.environment ⇒ String
Returns the current runtime environment name.
-
.hostname ⇒ String
Returns the system hostname.
-
.public_ipv4 ⇒ String
Returns the public IPv4 address of this machine.
-
.public_ipv6 ⇒ String
Returns the public IPv6 address of this machine.
-
.reset_cache! ⇒ void
Clears the memoized IP cache (useful in tests or when the IP may change).
Class Method Details
.environment ⇒ String
Returns the current runtime environment name. Checks RAILS_ENV, RACK_ENV, APP_ENV in order; falls back to "unknown".
49 50 51 |
# File 'lib/DhanHQ/utils/network_inspector.rb', line 49 def environment ENV["RAILS_ENV"] || ENV["RACK_ENV"] || ENV["APP_ENV"] || "unknown" end |
.hostname ⇒ String
Returns the system hostname.
41 42 43 |
# File 'lib/DhanHQ/utils/network_inspector.rb', line 41 def hostname Socket.gethostname end |
.public_ipv4 ⇒ String
Returns the public IPv4 address of this machine. Cached after the first successful lookup. Returns "unknown" on failure.
26 27 28 |
# File 'lib/DhanHQ/utils/network_inspector.rb', line 26 def public_ipv4 @public_ipv4 ||= fetch_ip(IPV4_URI) end |
.public_ipv6 ⇒ String
Returns the public IPv6 address of this machine. Cached after the first successful lookup. Returns "unknown" on failure.
34 35 36 |
# File 'lib/DhanHQ/utils/network_inspector.rb', line 34 def public_ipv6 @public_ipv6 ||= fetch_ip(IPV6_URI) end |
.reset_cache! ⇒ void
This method returns an undefined value.
Clears the memoized IP cache (useful in tests or when the IP may change).
56 57 58 59 |
# File 'lib/DhanHQ/utils/network_inspector.rb', line 56 def reset_cache! @public_ipv4 = nil @public_ipv6 = nil end |