Class: WebConsole::Permissions

Inherits:
Object
  • Object
show all
Defined in:
lib/web_console/permissions.rb

Constant Summary collapse

ALWAYS_PERMITTED_NETWORKS =

IPv4 and IPv6 localhost should be always allowed.

%w( 127.0.0.0/8 ::1 )

Instance Method Summary collapse

Constructor Details

#initialize(networks = nil) ⇒ Permissions

Returns a new instance of Permissions.



10
11
12
# File 'lib/web_console/permissions.rb', line 10

def initialize(networks = nil)
  @networks = normalize_networks(networks).map(&method(:coerce_network_to_ipaddr)).uniq
end

Instance Method Details

#include?(network) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/web_console/permissions.rb', line 14

def include?(network)
  @networks.any? { |permission| permission.include?(network.to_s) }
rescue IPAddr::InvalidAddressError
  false
end

#to_sObject



20
21
22
# File 'lib/web_console/permissions.rb', line 20

def to_s
  @networks.map(&method(:human_readable_ipaddr)).join(", ")
end