class Awspec::Helper::Finder::Subnet::SubnetCache

Usage

Includes Singleton module, so use instance instead of new to get a instance.

It is intended to be used internally by the find_subnet function only.

Many of the methods expect a symbol to search through the cache to avoid having to call to_sym multiple times.

Public Instance Methods

add_by_cidr(cidr, subnet_id) click to toggle source

Add a mapping of a CIDR to the respective subnet ID

# File lib/awspec/helper/finder/subnet.rb, line 31
def add_by_cidr(cidr, subnet_id)
  key_sym = cidr.to_sym
  @by_cidr[key_sym] = subnet_id.to_sym unless @by_cidr.key?(key_sym)
end
add_by_tag(tag, subnet_id) click to toggle source

Add a mapping of a tag to the respective subnet ID

# File lib/awspec/helper/finder/subnet.rb, line 37
def add_by_tag(tag, subnet_id)
  key_sym = tag.to_sym
  @by_tag_name[key_sym] = subnet_id.to_sym unless @by_tag_name.key?(key_sym)
end
add_subnet(subnet) click to toggle source

Add a Aws::EC2::Types::Subnet instance to the cache, mapping it’s ID to the instance itself.

# File lib/awspec/helper/finder/subnet.rb, line 44
def add_subnet(subnet)
  key_sym = subnet.subnet_id.to_sym
  @subnet_ids[key_sym] = subnet unless @subnet_ids.key?(key_sym)
end
empty?() click to toggle source

Check if the cache was already initialized or not.

# File lib/awspec/helper/finder/subnet.rb, line 80
def empty?
  @subnet_ids.empty?
end
has_cidr?(cidr_symbol) click to toggle source

Check if a IPv4 CIDR (as a symbol) exists in the cache.

# File lib/awspec/helper/finder/subnet.rb, line 55
def has_cidr?(cidr_symbol)
  @by_cidr.key?(cidr_symbol)
end
has_subnet?(subnet_id_symbol) click to toggle source

Check if a subnet ID (as a symbol) exists in the cache.

# File lib/awspec/helper/finder/subnet.rb, line 50
def has_subnet?(subnet_id_symbol)
  @subnet_ids.key?(subnet_id_symbol)
end
is_cidr?(subnet_id) click to toggle source

Check if a given string looks like a IPv4 CIDR.

# File lib/awspec/helper/finder/subnet.rb, line 75
def is_cidr?(subnet_id)
  @ip_matcher.match(subnet_id)
end
subnet_by_cidr(cidr_symbol) click to toggle source

Return a Aws::EC2::Types::Subnet that matches the given CIDR.

# File lib/awspec/helper/finder/subnet.rb, line 60
def subnet_by_cidr(cidr_symbol)
  @subnet_ids[@by_cidr[cidr_symbol]]
end
subnet_by_id(subnet_id_symbol) click to toggle source

Return a Aws::EC2::Types::Subnet that matches the given subnet ID.

# File lib/awspec/helper/finder/subnet.rb, line 70
def subnet_by_id(subnet_id_symbol)
  @subnet_ids[subnet_id_symbol]
end
subnet_by_tag(tag_symbol) click to toggle source

Return a Aws::EC2::Types::Subnet that matches the given tag.

# File lib/awspec/helper/finder/subnet.rb, line 65
def subnet_by_tag(tag_symbol)
  @subnet_ids[@by_tag_name[tag_symbol]]
end
to_s() click to toggle source

Return the cache as a string.

# File lib/awspec/helper/finder/subnet.rb, line 85
def to_s
  "by tag name: #{@by_tag_name}, by CIDR: #{@by_cidr}"
end