class Shift::InterfaceList

Public Class Methods

new(ifaces) click to toggle source

Create a new InterfaceList, given an array of class names of shift interfaces. Immutable once created.

# File lib/shift/interface_list.rb, line 7
def initialize(ifaces)
  @interfaces = ifaces
end

Public Instance Methods

==(other)
Alias for: eql?
eql?(other) click to toggle source
# File lib/shift/interface_list.rb, line 15
def eql?(other)
  @interfaces.eql? other.to_hash
end
Also aliased as: ==
hash() click to toggle source
# File lib/shift/interface_list.rb, line 20
def hash
  @interfaces.hash
end
inspect() click to toggle source
# File lib/shift/interface_list.rb, line 24
def inspect
  'InterfaceList' + @interfaces.inspect
end
pick() click to toggle source

Pick the preferred available interface.

@raise [DependencyError] when none of the interfaces

are available.

@return [Class] The preferred available class

# File lib/shift/interface_list.rb, line 35
def pick
  each_class {|kls| return kls if kls.available? }
  raise DependencyError, "nothing available: " +
    help_string
end
to_hash() click to toggle source
# File lib/shift/interface_list.rb, line 11
def to_hash
  @interfaces.dup
end

Private Instance Methods

each_class() { |get_iface(name)| ... } click to toggle source
# File lib/shift/interface_list.rb, line 52
def each_class
  @interfaces.each do |name|
    yield get_iface(name)
  end; nil
end
first_class() click to toggle source
# File lib/shift/interface_list.rb, line 58
def first_class
  get_iface(@interfaces.first)
end
get_iface(name) click to toggle source
# File lib/shift/interface_list.rb, line 62
def get_iface(name)
  Shift.const_get(name)
end
help_string() click to toggle source
# File lib/shift/interface_list.rb, line 43
def help_string
  if @interfaces.any?
    @interfaces.inspect + " Possible solution: " +
      first_class.instructions
  else
    'no interfaces mapped'
  end
end