Class: Icss::ProtocolSet
- Inherits:
-
Object
- Object
- Icss::ProtocolSet
- 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
-
#protocols ⇒ Object
Returns the value of attribute protocols.
Instance Method Summary collapse
-
#initialize ⇒ ProtocolSet
constructor
A new instance of ProtocolSet.
-
#load_protocol_set(protocol_set_filename) ⇒ Object
load and register the set of protocols in the given yaml file.
-
#load_protocols(*icss_filenames) ⇒ Object
load and register the protocols in the given filenames.
- #register(pr) ⇒ Object
Constructor Details
#initialize ⇒ ProtocolSet
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
#protocols ⇒ Object
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 |