Class: RSpecPuppetUtils::MockResource
- Inherits:
-
Object
- Object
- RSpecPuppetUtils::MockResource
- Defined in:
- lib/rspec_puppet_utils/mock_resource.rb
Overview
MockResource is an experimental feature, API may change! Use at your own risk… although feedback would be helpful :)
Instance Method Summary collapse
-
#initialize(name, resource_definition = {}) ⇒ MockResource
constructor
A new instance of MockResource.
- #join_vars(vars, join_string) ⇒ Object
- #normalise_value(value) ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(name, resource_definition = {}) ⇒ MockResource
Returns a new instance of MockResource.
7 8 9 10 |
# File 'lib/rspec_puppet_utils/mock_resource.rb', line 7 def initialize(name, resource_definition = {}) @name = name @resource_definition = resource_definition end |
Instance Method Details
#join_vars(vars, join_string) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rspec_puppet_utils/mock_resource.rb', line 26 def join_vars(vars, join_string) return '' unless vars parsed_vars = [] vars.each { |key, val| param = "$#{key}" value = normalise_value val val ? parsed_vars.push("#{param} = #{value}") : parsed_vars.push(param) } parsed_vars.join join_string end |
#normalise_value(value) ⇒ Object
37 38 39 40 |
# File 'lib/rspec_puppet_utils/mock_resource.rb', line 37 def normalise_value(value) # If string, wrap with quotes value.is_a?(String) ? "'#{value}'" : value end |
#render ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rspec_puppet_utils/mock_resource.rb', line 12 def render type = @resource_definition[:type] || :class vars = join_vars @resource_definition[:vars], "\n" if @resource_definition[:params].nil? param_section = '' else params = join_vars @resource_definition[:params], ', ' param_section = "( #{params} )" end "#{type} #{@name} #{param_section} { #{vars} }" end |