Class: Aikido::Zen::RuntimeSettings::IPSet
- Inherits:
-
Object
- Object
- Aikido::Zen::RuntimeSettings::IPSet
- Defined in:
- lib/aikido/zen/runtime_settings/ip_set.rb
Overview
Models a list of IP addresses or CIDR blocks, where we can check if a given address is part of any of the members.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #empty? ⇒ Boolean
- #include?(ip) ⇒ Boolean (also: #===)
-
#initialize(ips = Set.new) ⇒ IPSet
constructor
A new instance of IPSet.
Constructor Details
#initialize(ips = Set.new) ⇒ IPSet
Returns a new instance of IPSet.
13 14 15 |
# File 'lib/aikido/zen/runtime_settings/ip_set.rb', line 13 def initialize(ips = Set.new) @ips = ips.to_set end |
Class Method Details
.from_json(ips) ⇒ Object
9 10 11 |
# File 'lib/aikido/zen/runtime_settings/ip_set.rb', line 9 def self.from_json(ips) new(Array(ips).map { |ip| IPAddr.new(ip) }) end |
Instance Method Details
#==(other) ⇒ Object
26 27 28 |
# File 'lib/aikido/zen/runtime_settings/ip_set.rb', line 26 def ==(other) other.is_a?(RuntimeSettings::IPSet) && to_set == other.to_set end |
#empty? ⇒ Boolean
17 18 19 |
# File 'lib/aikido/zen/runtime_settings/ip_set.rb', line 17 def empty? @ips.empty? end |
#include?(ip) ⇒ Boolean Also known as: ===
21 22 23 |
# File 'lib/aikido/zen/runtime_settings/ip_set.rb', line 21 def include?(ip) @ips.any? { |pattern| pattern === ip } end |