Class: Distem::TopologyStore::TopologyWriter

Inherits:
StoreBase
  • Object
show all
Defined in:
lib/distem/topologystore/topologywriter.rb

Overview

Base interface for the saving methods. Based on the Visitor design pattern.

Direct Known Subclasses

HashWriter

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args)



8
9
10
# File 'lib/distem/topologystore/topologywriter.rb', line 8

def method_missing(method, *args)
  raise args[0].class.name
end

Instance Method Details

- (Object) visit(object)

Visit a resource object, automatically call the right method.

Attributes

  • object The Resource object

Returns

Object value of the kind of the concrete class (i.e. HashWriter returns an Hash object)



17
18
19
# File 'lib/distem/topologystore/topologywriter.rb', line 17

def visit( object )
  self.send( "visit_#{object.class.name.split('::').last.downcase}".to_sym, object )
end

- (Object) visit_array(array)

Visit an Array object, call the “visit” method for each values in the Hash.

Attributes

  • array The Array object

Returns

Object value of the kind of the concrete class (i.e. HashWriter returns an Hash object)



99
100
101
102
# File 'lib/distem/topologystore/topologywriter.rb', line 99

def visit_array(array)
  ret = array.collect { |val| visit(val) }
  return ret
end

- (Object) visit_bandwidth(limitbw)

:nodoc:



59
60
61
# File 'lib/distem/topologystore/topologywriter.rb', line 59

def visit_bandwidth(limitbw) # :nodoc:
  raise unless limitbw.is_a?(Resource::Bandwidth)
end

- (Object) visit_filesystem(filesystem)

:nodoc:



43
44
45
# File 'lib/distem/topologystore/topologywriter.rb', line 43

def visit_filesystem(filesystem) # :nodoc:
  raise unless filesystem.is_a?(Resource::FileSystem)
end

- (Object) visit_hash(hash)

Visit an Hash object, call the “visit” method for each values in the Hash.

Attributes

  • hash The Hash object

Returns

Object value of the kind of the concrete class (i.e. HashWriter returns an Hash object)



86
87
88
89
90
91
92
# File 'lib/distem/topologystore/topologywriter.rb', line 86

def visit_hash(hash)
  ret = {}
  hash.each_pair { |k,v|
    ret[k] = visit(v)
  }
  return ret
end

- (Object) visit_latency(limitlat)

:nodoc:



63
64
65
# File 'lib/distem/topologystore/topologywriter.rb', line 63

def visit_latency(limitlat) # :nodoc:
  raise unless limitlat.is_a?(Resource::Latency)
end

- (Object) visit_nilclass(obj)

:nodoc:



67
68
69
# File 'lib/distem/topologystore/topologywriter.rb', line 67

def visit_nilclass(obj) # :nodoc:
  return nil
end

- (Object) visit_pnode(pnode)

:nodoc:



31
32
33
# File 'lib/distem/topologystore/topologywriter.rb', line 31

def visit_pnode(pnode) # :nodoc:
  raise unless pnode.is_a?(Resource::PNode)
end

- (Object) visit_string(str)

Visit a String object

Attributes

  • str The String object

Returns

Object value of the kind of the concrete class (i.e. HashWriter returns an Hash object)



76
77
78
# File 'lib/distem/topologystore/topologywriter.rb', line 76

def visit_string(str)
  return str
end

- (Object) visit_viface(viface)

:nodoc:



39
40
41
# File 'lib/distem/topologystore/topologywriter.rb', line 39

def visit_viface(viface) # :nodoc:
  raise unless viface.is_a?(Resource::VIface)
end

- (Object) visit_vnetwork(vnetwork)

:nodoc:



47
48
49
# File 'lib/distem/topologystore/topologywriter.rb', line 47

def visit_vnetwork(vnetwork) # :nodoc:
  raise unless vnetwork.is_a?(Resource::VNetwork)
end

- (Object) visit_vnode(vnode)

:nodoc:



35
36
37
# File 'lib/distem/topologystore/topologywriter.rb', line 35

def visit_vnode(vnode) # :nodoc:
  raise unless vnode.is_a?(Resource::VNode)
end

- (Object) visit_vplatform(vplatform)

Visit a virtual platform object. All the other “visit_” methods are working the same way.

Attributes

*vplatform The VPlatform object

Returns

Object value of the kind of the concrete class (i.e. HashWriter returns an Hash object)



27
28
29
# File 'lib/distem/topologystore/topologywriter.rb', line 27

def visit_vplatform(vplatform)
  raise unless vplatform.is_a?(Resource::VPlatform)
end

- (Object) visit_vroute(vroute)

:nodoc:



51
52
53
# File 'lib/distem/topologystore/topologywriter.rb', line 51

def visit_vroute(vroute) # :nodoc:
  raise unless vroute.is_a?(Resource::VRoute)
end

- (Object) visit_vtraffic(vtraffic)

:nodoc:



55
56
57
# File 'lib/distem/topologystore/topologywriter.rb', line 55

def visit_vtraffic(vtraffic) # :nodoc:
  raise unless vtraffic.is_a?(Resource::VIface::VTraffic)
end