Class: Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/retrospec/resource.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type_name, instance) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
11
12
# File 'lib/retrospec/resource.rb', line 7

def initialize(type_name,instance)
  # we don't store the resource parameters in the variablestore because they are never referenced
  @parameters = Hash[instance.parameters.map { |k| [k.param, VariableStore.resolve(k.value).gsub("\"", '')]}]
  @type = type_name
  @title = VariableStore.resolve(instance.title).gsub("\"", '')
end

Instance Attribute Details

#parametersObject (readonly)

Returns the value of attribute parameters.



5
6
7
# File 'lib/retrospec/resource.rb', line 5

def parameters
  @parameters
end

#scope_nameObject (readonly)

Returns the value of attribute scope_name.



5
6
7
# File 'lib/retrospec/resource.rb', line 5

def scope_name
  @scope_name
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/retrospec/resource.rb', line 5

def title
  @title
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/retrospec/resource.rb', line 5

def type
  @type
end

Class Method Details

.all(statements) ⇒ Object

Gets all resources in the type that are not in a code block



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/retrospec/resource.rb', line 15

def self.all(statements)
  if statements.respond_to?(:code)
    # if we accidentally pass a type in without specifying the code
    statements = statements.code unless statements.nil?
  end
  a = []
  # sometimes the code is empty
  if statements.respond_to?(:find_all)
    res = statements.find_all { |s| s.instance_of?(Puppet::Parser::AST::Resource)}
    res.each do |r|
      r.instances.each do |i|
        a << Resource.new(r.type, i)
      end
    end
  end
  a
end

.all_resourcesObject



33
34
35
# File 'lib/retrospec/resource.rb', line 33

def self.all_resources
  ObjectSpace.each_object(Puppet::Parser::AST::Resource).map {|x| x}
end