Sha256: fe306f0f8f2835fbd27155b389f2ac981af3805af25c60511b0ceb7ba07a9035

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

require_relative 'variable_store'

class Resource

  attr_reader :type, :title, :parameters, :scope_name

  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

  # Gets all resources in the type that are not in a code block
  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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
puppet-retrospec-0.11.0 lib/retrospec/plugins/v1/plugin/resource.rb
puppet-retrospec-0.10.0 lib/retrospec/plugins/v1/plugin/resource.rb
puppet-retrospec-0.9.1 lib/retrospec/plugins/v1/plugin/resource.rb
puppet-retrospec-0.9.0 lib/retrospec/plugins/v1/plugin/resource.rb