Class SSHMenu::HostItem
In: lib/sshmenu.rb  (Git)
Parent: Item

The SSHMenu::HostItem is used as a container for the configuration options associated with a host item on the main menu.

Accessors are provided for the following properties (corresponding to input elements in the ‘Edit Host’ dialog):

  • title
  • sshparams
  • geometry
  • enable_bcvi

Inherits from SSHMenu::Item.


Public Class methods

Defines a list of attribute names for which accessor methods are generated


# File lib/sshmenu.rb, line 1621
    def HostItem.attributes
      [ :title, :sshparams, :geometry, :enable_bcvi ]

Generates accessor methods


# File lib/sshmenu.rb, line 1627
    def HostItem.make_accessors
      self.attributes.each { |a| attr(a, true) }

Typically called from SSHMenu::Item#new_from_hash. Retains a copy of the whole attributes hash, allowing unrecognised attributes from the config file to be retained.


# File lib/sshmenu.rb, line 1641
    def initialize(h={})
      @type = 'host'
      @hash = h.dup
      self.class.attributes.each { |a| self.send("#{a}=", h[a] || h[a.to_s]) }

Public Instance methods

Returns a deep copy of the current host item.


# File lib/sshmenu.rb, line 1649
    def dup

Returns the initial part of the ‘sshparams’ property which defines environment settings - may be an empty string.


# File lib/sshmenu.rb, line 1667
    def env_settings
      return sshparams =~ /^((?:\w+="(?:\\"|[^"])*" +)*)/ ? $1 : ''

Returns the ‘sshparams’ property without the initial environment settings section.


# File lib/sshmenu.rb, line 1674
    def sshparams_noenv
      return sshparams =~ /^(?:\w+="(?:\\"|[^"])*" +)*(.*)$/ ? $1 : ''

Serialises the host item to a hash (including keys for any unknown attributes which were read in from the config file).


# File lib/sshmenu.rb, line 1656
    def to_h
      h = @hash
      h['type'] = 'host'
      self.class.attributes.each { |a| h[a.to_s] = self.send(a) }
      h.delete('enable_bcvi') unless enable_bcvi
      return h