Class: Tinet::Data
- Inherits:
-
Object
- Object
- Tinet::Data
- Defined in:
- lib/tinet/data.rb
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#switches ⇒ Object
readonly
Returns the value of attribute switches.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(nodes, switches, options) ⇒ Data
constructor
A new instance of Data.
Constructor Details
#initialize(nodes, switches, options) ⇒ Data
Returns a new instance of Data.
48 49 50 51 52 |
# File 'lib/tinet/data.rb', line 48 def initialize(nodes, switches, ) @nodes = nodes @switches = switches @options = end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
43 44 45 |
# File 'lib/tinet/data.rb', line 43 def nodes @nodes end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
43 44 45 |
# File 'lib/tinet/data.rb', line 43 def @options end |
#switches ⇒ Object (readonly)
Returns the value of attribute switches.
43 44 45 |
# File 'lib/tinet/data.rb', line 43 def switches @switches end |
Class Method Details
.parse(yaml_path) ⇒ Tinet::Data
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/tinet/data.rb', line 10 def parse(yaml_path) yaml = YAML.load_file(yaml_path) raise InvalidYAMLError, "Nodes must be array" unless yaml['nodes'].is_a?(Array) raise InvalidYAMLError, "Switches must be array" unless yaml['switches'].is_a?(Array) namespace = yaml.fetch('meta', {}).fetch('namespace', nil) Tinet.namespace = namespace unless namespace.nil? || namespace.empty? nodes = yaml['nodes'].map { |node| Tinet::Node.parse(node) } switches = yaml['switches'].map { |switch| Tinet::Switch.parse(switch) } = { pre_cmd: fetch(yaml, 'pre_cmd'), pre_init: fetch(yaml, 'pre_init'), post_init: fetch(yaml, 'post_init'), pre_conf: fetch(yaml, 'pre_conf'), post_conf: fetch(yaml, 'post_conf'), pre_down: fetch(yaml, 'pre_down'), post_down: fetch(yaml, 'post_down') } self.new(nodes, switches, ) end |