Class: Retrospec::Puppet::SpecObject

Inherits:
Retrospec::Plugins::V1::ContextObject
  • Object
show all
Defined in:
lib/retrospec/plugins/v1/plugin/spec_object.rb

Overview

this object is passed to the templates for erb template rendering you can use data contained in this object in your templates

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mod_path, instance_data, config_data) ⇒ SpecObject

Returns a new instance of SpecObject.

Parameters:

  • mod_path (String)
    • the path to the module

  • instance_data (Hash)
  • config_data (Hash)
    • retrospec config data from config file and cli



13
14
15
16
17
18
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 13

def initialize(mod_path, instance_data, config_data)
  @instance = instance_data
  @config = config_data
  @module_path = mod_path
  all_hiera_data
end

Instance Attribute Details

#all_hiera_dataHash (readonly)

Note:

this stays in memory, which should not cause a problem when the program

does not search for manual lookups using the hiera or lookup function quits and the user wants to run again, but if some external tool keeps this in memory the data would never be refreshed

Parameters:

  • - (String)

    the name of the hostclass

Returns:

  • (Hash)
    • return a hash of all the params found in all hostclasses



56
57
58
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 56

def all_hiera_data
  @all_hiera_data
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 7

def config
  @config
end

#enable_beaker_testsObject

Returns the value of attribute enable_beaker_tests.



8
9
10
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 8

def enable_beaker_tests
  @enable_beaker_tests
end

#instanceObject (readonly)

Returns the value of attribute instance.



7
8
9
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 7

def instance
  @instance
end

#module_nameString (readonly)

Returns - the name of the module.

Returns:

  • (String)
    • the name of the module



21
22
23
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 21

def module_name
  @module_name
end

#module_pathObject (readonly)

Returns the value of attribute module_path.



7
8
9
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 7

def module_path
  @module_path
end

#parametersObject

Returns the value of attribute parameters.



8
9
10
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 8

def parameters
  @parameters
end

#resourcesObject

Returns the value of attribute resources.



8
9
10
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 8

def resources
  @resources
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 8

def type
  @type
end

#typesArray

this is a list of defined and class types

Returns:

  • (Array)
    • returns an array of puppet types found in the manfiests



27
28
29
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 27

def types
  @types
end

Instance Method Details

#class_hiera_data(classname) ⇒ Hash

does not search for manual lookups using the hiera or lookup function

Parameters:

  • - (String)

    the name of the hostclass

Returns:

  • (Hash)
    • return a hash of all the params found in provided hostclass only



34
35
36
37
38
39
40
41
42
43
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 34

def class_hiera_data(classname)
  data = {}
  found_type = host_classes.find { |t| t.name == classname }
  return data unless found_type
  found_type.arguments.each do |k, _v|
    key = "#{found_type.name}::#{k}"
    data[key] = nil
  end
  data
end

#enable_beaker_tests?Boolean

Returns - true if the user wants to enable beaker tests.

Returns:

  • (Boolean)
    • true if the user wants to enable beaker tests



68
69
70
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 68

def enable_beaker_tests?
  config[:enable_beaker_tests]
end

#fact_nameObject



80
81
82
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 80

def fact_name
  instance[:name]
end

#host_classesArray

Returns - an array of all the hostclasses.

Returns:

  • (Array)
    • an array of all the hostclasses



46
47
48
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 46

def host_classes
  types.find_all { |t| t.type == :hostclass }
end

#variable_value(variable_name) ⇒ String

allows the user to use the variable store to resolve the variable if it exists looks up the varible name in the variable store

Parameters:

  • - (String)

    the name of the variable

Returns:

  • (String)
    • the value of the variable if found other returns variable



76
77
78
# File 'lib/retrospec/plugins/v1/plugin/spec_object.rb', line 76

def variable_value(variable_name)
  VariableStore.resolve(variable_name)
end