Class: ChefSpec::Renderer

Inherits:
Object
  • Object
show all
Includes:
Normalize
Defined in:
lib/chefspec/renderer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Normalize

#resource_name

Constructor Details

#initialize(chef_run, resource) ⇒ Renderer

Create a new Renderer for the given Chef run and resource.

Parameters:

  • chef_run (Chef::Runner)

    the Chef run containing the resources

  • resource (Chef::Resource)

    the resource to render content from



25
26
27
28
# File 'lib/chefspec/renderer.rb', line 25

def initialize(chef_run, resource)
  @chef_run = chef_run
  @resource = resource
end

Instance Attribute Details

#chef_runChef::Runner (readonly)

Returns:

  • (Chef::Runner)


12
13
14
# File 'lib/chefspec/renderer.rb', line 12

def chef_run
  @chef_run
end

#resourceChef::Resource (readonly)

Returns:

  • (Chef::Resource)


15
16
17
# File 'lib/chefspec/renderer.rb', line 15

def resource
  @resource
end

Instance Method Details

#contentString?

The content of the resource (this method delegates to the) various private rendering methods.

Returns:

  • (String, nil)

    the contents of the file as a string, or nil if the resource does not contain or respond to a content renderer.



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/chefspec/renderer.rb', line 38

def content
  case resource_name(resource)
  when :template
    content_from_template(chef_run, resource)
  when :file
    content_from_file(chef_run, resource)
  when :cookbook_file
    content_from_cookbook_file(chef_run, resource)
  else
    nil
  end
end