Class: Y2Network::ConnectionConfigsCollection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Yast::Logger
Defined in:
src/lib/y2network/connection_configs_collection.rb

Overview

A container for connection configurations objects.

Examples:

Create a new collection

eth0 = Y2Network::ConnectionConfig::Ethernet.new
collection = Y2Network::ConnectionConfigsCollection.new([eth0])

Find a connection config using its name

config = collection.by_name("eth0") #=> #<Y2Network::ConnectionConfig::Ethernet:0x...>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_configs = []) ⇒ ConnectionConfigsCollection

Constructor


45
46
47
# File 'src/lib/y2network/connection_configs_collection.rb', line 45

def initialize(connection_configs = [])
  @connection_configs = connection_configs
end

Instance Attribute Details

#connection_configsObject (readonly) Also known as: to_a

Returns the value of attribute connection_configs


36
37
38
# File 'src/lib/y2network/connection_configs_collection.rb', line 36

def connection_configs
  @connection_configs
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Compares ConnectionConfigsCollection


109
110
111
# File 'src/lib/y2network/connection_configs_collection.rb', line 109

def ==(other)
  ((connection_configs - other.connection_configs) + (other.connection_configs - connection_configs)).empty?
end

#add_or_update(connection_config) ⇒ Object

Note:

It uses the name to do the matching.

Adds or updates a connection configuration


78
79
80
81
82
83
84
85
# File 'src/lib/y2network/connection_configs_collection.rb', line 78

def add_or_update(connection_config)
  idx = connection_configs.find_index { |c| c.name == connection_config.name }
  if idx
    connection_configs[idx] = connection_config
  else
    connection_configs << connection_config
  end
end

#by_ids(*ids) ⇒ Array<ConnectionConfig::Base>

Returns connections with any of the given internal IDs


69
70
71
# File 'src/lib/y2network/connection_configs_collection.rb', line 69

def by_ids(*ids)
  select { |c| ids.include?(c.id) }
end

#by_interface(interface_name) ⇒ Array<ConnectionConfig::Base>

Returns connection configurations which are associated to the given interface


61
62
63
# File 'src/lib/y2network/connection_configs_collection.rb', line 61

def by_interface(interface_name)
  connection_configs.select { |c| c.interface == interface_name }
end

#by_name(name) ⇒ ConnectionConfig::Base?

Returns a connection configuration with the given name if present


53
54
55
# File 'src/lib/y2network/connection_configs_collection.rb', line 53

def by_name(name)
  connection_configs.find { |c| c.name == name }
end

#remove(connection_config) ⇒ Object

Note:

It uses the name to do the matching.

Removes a connection configuration


92
93
94
95
# File 'src/lib/y2network/connection_configs_collection.rb', line 92

def remove(connection_config)
  name = connection_config.respond_to?(:name) ? connection_config.name : connection_config
  connection_configs.reject! { |c| c.name == name }
end

#select(&block) ⇒ ConnectionConfigsCollection

Selects connections which satisfy the given +block+


101
102
103
# File 'src/lib/y2network/connection_configs_collection.rb', line 101

def select(&block)
  self.class.new(to_a.select(&block))
end