Class: Inspec::Plugins::Resource

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.__register(name, obj) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/inspec/plugins/resource.rb', line 13

def self.__register(name, obj)
  # rubocop:disable Lint/NestedMethodDefinition
  cl = Class.new(obj) do
    # add some common methods
    include Inspec::Plugins::ResourceCommon
    def initialize(backend, name, *args)
      # attach the backend to this instance
      @__backend_runner__ = backend
      @__resource_name__ = name
      # call the resource initializer
      super(*args)
    end

    def inspec
      @__backend_runner__
    end
  end
  # rubocop:enable Lint/NestedMethodDefinition

  # add the resource to the registry by name
  Inspec::Resource.registry[name] = cl
end

.name(name = nil) ⇒ Object



8
9
10
11
# File 'lib/inspec/plugins/resource.rb', line 8

def self.name(name = nil)
  return if name.nil?
  Inspec::Plugins::Resource.__register(name, self)
end

Instance Method Details

#inspectString

Overwrite inspect to provide better output to RSpec results.

Returns:

  • (String)

    full name of the resource



47
48
49
# File 'lib/inspec/plugins/resource.rb', line 47

def inspect
  to_s
end

#to_sObject

Print the name of the resource



40
41
42
# File 'lib/inspec/plugins/resource.rb', line 40

def to_s
  @__resource_name__
end