Class: SNMPPass::Variable Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/snmp_pass/variable.rb,
lib/snmp_pass/variable/oid.rb,
lib/snmp_pass/variable/gauge.rb,
lib/snmp_pass/variable/string.rb,
lib/snmp_pass/variable/counter.rb,
lib/snmp_pass/variable/integer.rb,
lib/snmp_pass/variable/ip_address.rb,
lib/snmp_pass/variable/time_ticks.rb

Overview

This class is abstract.

Parent class for variables. Which store the information returned by PassPersist.

Direct Known Subclasses

Counter, Gauge, IPAddress, Integer, OID, String, TimeTicks

Defined Under Namespace

Classes: Counter, Gauge, IPAddress, Integer, OID, String, TimeTicks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(getter:, setter: 'not-writable') ⇒ Variable

Create a new variable.

Parameters:

  • getter (Proc, #to_s)

    The value of the variable, if a Proc it gets run to get the value (which must respond to to_s)


21
22
23
24
# File 'lib/snmp_pass/variable.rb', line 21

def initialize(getter:, setter: 'not-writable')
  @getter = getter
  @setter = setter
end

Instance Attribute Details

#getterObject (readonly)

Returns the value of attribute getter


8
9
10
# File 'lib/snmp_pass/variable.rb', line 8

def getter
  @getter
end

#setterObject (readonly)

Returns the value of attribute setter


16
17
18
# File 'lib/snmp_pass/variable.rb', line 16

def setter
  @setter
end

#valueString (readonly)

Returns the type of the variable.

Returns:

  • (String)

    the type of the variable


44
45
46
# File 'lib/snmp_pass/variable.rb', line 44

def type
  self.class.name.split('::').last.downcase
end

Instance Method Details

#get_valueString

Get the value of the variable.

Returns:


28
29
30
# File 'lib/snmp_pass/variable.rb', line 28

def get_value
  getter.is_a?(Proc) ? getter.call.to_s : getter.to_s
end

#set_value(type, value) ⇒ String

Set the value of the variable.

Parameters:

  • type (String)

    the type being set ()

  • value (String)

    the string representation of the value to set

Returns:

  • (String)

    returned by the setter proc


36
37
38
39
40
# File 'lib/snmp_pass/variable.rb', line 36

def set_value(type, value)
  return 'wrong-type' unless type.eql?(self.type)
  return setter if setter.is_a?(::String)
  setter.call(value.to_s).to_s
end

#typeObject


44
45
46
# File 'lib/snmp_pass/variable.rb', line 44

def type
  self.class.name.split('::').last.downcase
end