Class: Clusterfuck::SubnetFactory
- Inherits:
-
Object
- Object
- Clusterfuck::SubnetFactory
- Defined in:
- lib/clusterfuck/subnet_factory.rb
Constant Summary collapse
- START_SUBNET =
"10.0.39.0/24"
Instance Attribute Summary collapse
-
#last_ip ⇒ Object
readonly
Returns the value of attribute last_ip.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(last_ip) ⇒ SubnetFactory
constructor
A new instance of SubnetFactory.
- #next_ip ⇒ Object
Constructor Details
#initialize(last_ip) ⇒ SubnetFactory
Returns a new instance of SubnetFactory.
8 9 10 |
# File 'lib/clusterfuck/subnet_factory.rb', line 8 def initialize(last_ip) @last_ip = last_ip end |
Instance Attribute Details
#last_ip ⇒ Object (readonly)
Returns the value of attribute last_ip.
3 4 5 |
# File 'lib/clusterfuck/subnet_factory.rb', line 3 def last_ip @last_ip end |
Class Method Details
.next_subnet(cidr = 24) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/clusterfuck/subnet_factory.rb', line 16 def self.next_subnet(cidr = 24) # `succ` twice to start at x.x.2.1, for example: # 10.0.39.1 -> 10.0.40.1 @previous = @previous.mask(cidr).to_range.last.succ.succ SubnetFactory.new(@previous) end |
.reset ⇒ Object
23 24 25 |
# File 'lib/clusterfuck/subnet_factory.rb', line 23 def self.reset @previous = IPAddr.new(START_SUBNET) end |
Instance Method Details
#next_ip ⇒ Object
12 13 14 |
# File 'lib/clusterfuck/subnet_factory.rb', line 12 def next_ip @last_ip = @last_ip.succ end |