Class: LocalIPChecker::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/local_ip_checker/executor.rb

Constant Summary collapse

HOST_IP_ADDRESSES =
(%w[0.0.0.0 ::] + Socket.ip_address_list.map(&:ip_address)).freeze
IPV6_LINKLOCAL_ADDRESSES =
IPAddr.new("169.254.0.0/16").freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Executor

Returns a new instance of Executor.



20
21
22
# File 'lib/local_ip_checker/executor.rb', line 20

def initialize(value)
  @value = value
end

Class Method Details

.local?(value) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/local_ip_checker/executor.rb', line 11

def local?(value)
  new(value).local?
end

.nonlocal?(value) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/local_ip_checker/executor.rb', line 15

def nonlocal?(value)
  !local?(value)
end

Instance Method Details

#local?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
# File 'lib/local_ip_checker/executor.rb', line 24

def local?
  Enumerator.new do |enum|
    enum << localhost?
    enum << loopback?
    enum << local_network?
    enum << link_local?
  end.any?(&:itself)
end