Class: AbideDataProcessor::Parser::Resource
- Inherits:
-
ProcessorObject
- Object
- ProcessorObject
- AbideDataProcessor::Parser::Resource
- Defined in:
- lib/abide-data-processor/parser.rb
Overview
This class represents a single Puppet resource (class, defined type, etc.)
Instance Attribute Summary collapse
-
#control_names ⇒ Object
readonly
Returns the value of attribute control_names.
-
#controls ⇒ Object
readonly
Returns the value of attribute controls.
-
#mapped_control_names ⇒ Object
readonly
Returns the value of attribute mapped_control_names.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#add_control_configs(control_configs) ⇒ Object
Adds overriding parameter values to controls in this resource if this resource has a matching control.
-
#control?(control_name) ⇒ Boolean
This method checks if this Resource contains the given control.
-
#initialize(name, data, control_maps) ⇒ Resource
constructor
A new instance of Resource.
-
#param?(param_name) ⇒ Boolean
This method checks if this Resource contains the given parameter.
-
#resource_data ⇒ Object
Outputs a representation of this object as a Hash usable by Puppet’s create_resources function.
-
#resource_reference ⇒ String
This method returns a string representation of this Resource in the resource reference format used by Puppet.
Methods inherited from ProcessorObject
#after_me, #before_me, #inspect, #name?, #to_s
Methods included from Validation
#array_of_hashes?, #not_nil_or_empty?, #validate_control_maps, #validate_hiera_data
Constructor Details
#initialize(name, data, control_maps) ⇒ Resource
Returns a new instance of Resource.
528 529 530 531 532 533 534 535 |
# File 'lib/abide-data-processor/parser.rb', line 528 def initialize(name, data, control_maps) super(name, data, control_maps) @type = @data['type'] @controls = create_control_classes(@data['controls']) @control_names = Set.new(@controls.map(&:name)).flatten @mapped_control_names = Set.new(@controls.map(&:mapped_names).flatten).flatten end |
Instance Attribute Details
#control_names ⇒ Object (readonly)
Returns the value of attribute control_names.
526 527 528 |
# File 'lib/abide-data-processor/parser.rb', line 526 def control_names @control_names end |
#controls ⇒ Object (readonly)
Returns the value of attribute controls.
526 527 528 |
# File 'lib/abide-data-processor/parser.rb', line 526 def controls @controls end |
#mapped_control_names ⇒ Object (readonly)
Returns the value of attribute mapped_control_names.
526 527 528 |
# File 'lib/abide-data-processor/parser.rb', line 526 def mapped_control_names @mapped_control_names end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
526 527 528 |
# File 'lib/abide-data-processor/parser.rb', line 526 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
526 527 528 |
# File 'lib/abide-data-processor/parser.rb', line 526 def type @type end |
Instance Method Details
#add_control_configs(control_configs) ⇒ Object
Adds overriding parameter values to controls in this resource if this resource has a matching control.
540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/abide-data-processor/parser.rb', line 540 def add_control_configs(control_configs) control_configs.each do |control, configs| next unless control?(control) @controls.each do |control_class| next unless control_class.name?(control) control_class.resource_params.deep_merge!(configs) end end end |
#control?(control_name) ⇒ Boolean
This method checks if this Resource contains the given control.
578 579 580 |
# File 'lib/abide-data-processor/parser.rb', line 578 def control?(control_name) @control_names.include?(control_name) || @mapped_control_names.include?(control_name) end |
#param?(param_name) ⇒ Boolean
This method checks if this Resource contains the given parameter.
585 586 587 588 589 590 591 |
# File 'lib/abide-data-processor/parser.rb', line 585 def param?(param_name) if param_name.respond_to?(:each) param_name.all? { |name| param?(name) } else @param_names.include?(param_name) end end |
#resource_data ⇒ Object
Outputs a representation of this object as a Hash usable by Puppet’s create_resources function.
554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/abide-data-processor/parser.rb', line 554 def resource_data control_params = control_parameters METAPARAMS.each do |mparam| next if mparam == 'dependent' refs = resource_references(mparam, control_params) next if refs.nil? control_params[mparam] = refs end { @type => { @name => control_params } } end |
#resource_reference ⇒ String
This method returns a string representation of this Resource in the resource reference format used by Puppet.
570 571 572 573 |
# File 'lib/abide-data-processor/parser.rb', line 570 def resource_reference type_ref = @type.split('::').map(&:capitalize).join('::') "#{type_ref}['#{@name}']" end |