Class: Icss::ProtocolSet

Inherits:
Object
  • Object
show all
Defined in:
lib/icss/protocol_set.rb

Overview

Holds a set of icss protocols, with helper methods to load them from a directory tree, to merge in a protocol set yaml file, and so forth

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProtocolSet

Returns a new instance of ProtocolSet.



11
12
13
# File 'lib/icss/protocol_set.rb', line 11

def initialize
  self.protocols = {}
end

Instance Attribute Details

#protocolsObject

Returns the value of attribute protocols.



9
10
11
# File 'lib/icss/protocol_set.rb', line 9

def protocols
  @protocols
end

Instance Method Details

#load_protocol_set(protocol_set_filename) ⇒ Object

load and register the set of protocols in the given yaml file. it must be a hash with element ‘protocol_set’, holding an array of protocol hashes.

protocol_set:
  - namespace: "..."
    protocol:  "..."


39
40
41
42
43
44
# File 'lib/icss/protocol_set.rb', line 39

def load_protocol_set protocol_set_filename
  protocol_set_hsh = YAML.load(File.open(protocol_set_filename))
  protocol_set_hsh['protocol_set'].each do |hsh|
    register Icss::Protocol.receive(hsh)
  end
end

#load_protocols(*icss_filenames) ⇒ Object

load and register the protocols in the given filenames



25
26
27
28
29
30
# File 'lib/icss/protocol_set.rb', line 25

def load_protocols *icss_filenames
  icss_filenames = icss_filenames.flatten.compact
  icss_filenames.each do |icss_filename|
    register Icss::Protocol.receive_from_file(icss_filename)
  end
end

#register(pr) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/icss/protocol_set.rb', line 16

def register pr
  if protocols[pr.fullname]
    protocols[pr.fullname].tree_merge!(pr)
  else
    protocols[pr.fullname] = pr
  end
end