Class: RSpecSystem::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec-system/node.rb

Overview

This class represents a node in a nodeset

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Node

Create a new node object.

Parameters:

  • options (Hash)

    options for new node

Options Hash (options):

  • :name (String)

    name of node. Mandatory.

  • :prefab (String)

    prefab setting. Mandatory.

  • :options (String)

    options setting. Optional.

  • :nodeset (RSpecSystem::NodeSet)

    the parent nodeset for this node. Mandatory.

  • :custom_prefabs_path (String)

    path of custom prefabs yaml file. Optional.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rspec-system/node.rb', line 34

def initialize(options)
  @name = options[:name]
  prefab = options[:prefab]
  @options = options[:options]
  @nodeset = options[:nodeset]
  @custom_prefabs_path = options[:custom_prefabs_path]

  if prefab.nil?
    # TODO: do not support not prefabs yet
    raise "No prefab defined, bailing"
  else
    @prefab = RSpecSystem::Prefab.prefab(prefab, @custom_prefabs_path)
    @facts = @prefab.facts
    @provider_specifics = @prefab.provider_specifics
  end
end

Class Method Details

.node_from_yaml(nodeset, k, v, custom_prefabs_path) ⇒ RSpecSystem::Node

Static helper for generating a node direct from the hash returned by the nodeset YAML file.

Parameters:

  • nodeset (RSpecSystem::Node)

    nodeset that this node belongs to

  • k (String)

    name of node

  • v (Hash<String,String>)

    hash configuration as given from the nodeset yaml file

  • custom_prefabs_path (String)

    path of custom prefabs yaml file

Returns:



14
15
16
17
18
19
20
21
22
# File 'lib/rspec-system/node.rb', line 14

def self.node_from_yaml(nodeset, k, v, custom_prefabs_path)
  RSpecSystem::Node.new(
    :nodeset => nodeset,
    :custom_prefabs_path => custom_prefabs_path,
    :name => k,
    :prefab => v['prefab'],
    :options => v['options']
  )
end

Instance Method Details

#factsHash

Retreives facts from the nodeset definition or prefab.

Returns:

  • (Hash)

    returns a hash of facter facts defined for this node



75
76
77
# File 'lib/rspec-system/node.rb', line 75

def facts
  @facts
end

#inspectString

Return name when inspected

Returns:

  • (String)

    name of node



103
104
105
# File 'lib/rspec-system/node.rb', line 103

def inspect
  name
end

#nameString

Returns the name of the node as specified in the nodeset file.

Returns:

  • (String)

    name of node



54
55
56
# File 'lib/rspec-system/node.rb', line 54

def name
  @name
end

#nodesetRSpecSystem::NodeSet

Returns the nodeset this node belongs in.

Returns:



82
83
84
# File 'lib/rspec-system/node.rb', line 82

def nodeset
  @nodeset
end

#optionsHash

Returns the custom object for this node (if any).

Returns:

  • (Hash)

    the options object used to customize the node



68
69
70
# File 'lib/rspec-system/node.rb', line 68

def options
  @options
end

#prefabRSpecSystem::Prefab

Returns the prefab object for this node (if any).

Returns:



61
62
63
# File 'lib/rspec-system/node.rb', line 61

def prefab
  @prefab
end

#provider_specificsHash

Return provider specific settings

Returns:

  • (Hash)

    provider specific settings



89
90
91
# File 'lib/rspec-system/node.rb', line 89

def provider_specifics
  @provider_specifics
end

#to_sString

Return name when stringified

Returns:

  • (String)

    name of node



96
97
98
# File 'lib/rspec-system/node.rb', line 96

def to_s
  name
end