Class: Snmp2mkr::ConfigTypes::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/snmp2mkr/config_types/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, context: {}) ⇒ Base

Returns a new instance of Base.



4
5
6
7
8
# File 'lib/snmp2mkr/config_types/base.rb', line 4

def initialize(obj, context: {})
  @original = obj
  setup obj
  self.binded_context = context
end

Instance Attribute Details

#binded_contextObject

Returns the value of attribute binded_context.



27
28
29
# File 'lib/snmp2mkr/config_types/base.rb', line 27

def binded_context
  @binded_context
end

Instance Method Details

#bind_context(ctx) ⇒ Object



29
30
31
# File 'lib/snmp2mkr/config_types/base.rb', line 29

def bind_context(ctx)
  self.class.new(@original, context: ctx)
end

#children(type = nil) ⇒ Object



18
19
20
21
# File 'lib/snmp2mkr/config_types/base.rb', line 18

def children(type = nil)
  @children ||= collect_children.flat_map { |ch| ch.kind_of?(Base) ? [ch, *ch.children] : [ch] }
  type ? @children.select { |_| type === _ } : @children
end

#collect_childrenObject



23
24
25
# File 'lib/snmp2mkr/config_types/base.rb', line 23

def collect_children
  []
end

#evaluate(context: binded_context, previous: nil) ⇒ Object



14
15
16
# File 'lib/snmp2mkr/config_types/base.rb', line 14

def evaluate(context: binded_context, previous: nil)
  value
end

#inspectObject



10
11
12
# File 'lib/snmp2mkr/config_types/base.rb', line 10

def inspect
  "#<#{self.class}: #{@original.inspect} (#{@binded_context.inspect})>"
end