Class: Inspec::Plugins::Resource
- Inherits:
-
Object
- Object
- Inspec::Plugins::Resource
- Defined in:
- lib/inspec/plugins/resource.rb
Class Method Summary collapse
- .__register(name, obj) ⇒ Object
- .desc(description = nil) ⇒ Object
- .example(example = nil) ⇒ Object
- .name(name = nil) ⇒ Object
Instance Method Summary collapse
-
#inspect ⇒ String
Overwrite inspect to provide better output to RSpec results.
-
#to_s ⇒ Object
Print the name of the resource.
Class Method Details
.__register(name, obj) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/inspec/plugins/resource.rb', line 26 def self.__register(name, obj) # rubocop:disable Lint/NestedMethodDefinition, Lint/DuplicateMethods 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 self.desc(description = nil) return @description if description.nil? @description = description end def self.example(example = nil) return @example if example.nil? @example = example end def inspec @__backend_runner__ end end # rubocop:enable Lint/NestedMethodDefinition # add the resource to the registry by name with a newly-named registry class klass_name = name.split('_').map(&:capitalize).join Inspec::Resource::Registry.const_set(klass_name, cl) Inspec::Resource.registry[name] = Inspec::Resource::Registry.const_get(klass_name) end |
.desc(description = nil) ⇒ Object
16 17 18 19 |
# File 'lib/inspec/plugins/resource.rb', line 16 def self.desc(description = nil) return if description.nil? Inspec::Resource.registry[@name].desc(description) end |
.example(example = nil) ⇒ Object
21 22 23 24 |
# File 'lib/inspec/plugins/resource.rb', line 21 def self.example(example = nil) return if example.nil? Inspec::Resource.registry[@name].example(example) end |
.name(name = nil) ⇒ Object
10 11 12 13 14 |
# File 'lib/inspec/plugins/resource.rb', line 10 def self.name(name = nil) return if name.nil? @name = name Inspec::Plugins::Resource.__register(name, self) end |
Instance Method Details
#inspect ⇒ String
Overwrite inspect to provide better output to RSpec results.
72 73 74 |
# File 'lib/inspec/plugins/resource.rb', line 72 def inspect to_s end |
#to_s ⇒ Object
Print the name of the resource
65 66 67 |
# File 'lib/inspec/plugins/resource.rb', line 65 def to_s @__resource_name__ end |