Module: AbideDataProcessor::Parser

Defined in:
lib/abide-data-processor/parser.rb

Overview

This module contains the logic for creating resource data from Hiera data.

Defined Under Namespace

Modules: Validation Classes: Control, ProcessorObject, Resource, ResourceDataParser

Constant Summary collapse

MAP_TYPES =
%w[hiera_title hiera_title_num number title].freeze
METAPARAMS =
%w[dependent before require subscribe notify].freeze

Class Method Summary collapse

Class Method Details

.clear_cacheObject

Clears the current cache. Used in testing.



714
715
716
# File 'lib/abide-data-processor/parser.rb', line 714

def clear_cache
  @object_cache = {}
end

.new_control(control_name, control_data, control_maps) ⇒ Control

Creates a new Control object. If an object with the same control name, control data, and control maps already exists, it will be returned instead of creating a new one.

Parameters:

  • control_name (String)

    The name of the control.

  • control_data (Hash)

    The data for the control.

  • control_maps (Array)

    The control maps for the control.

Returns:

  • (Control)

    The new or cached Control object.



699
700
701
702
703
704
705
706
707
708
709
710
711
# File 'lib/abide-data-processor/parser.rb', line 699

def new_control(control_name, control_data, control_maps)
  cache_key = [Control.name, control_name, control_data, control_maps]
  cached = cache_get(cache_key)
  return cached unless cached.nil?

  begin
    new_control = Control.new(control_name, control_data, control_maps)
  rescue ArgumentError => e
    raise ArgumentError, "Failed to create control #{control_name}: #{e.message}"
  end
  cache_add(cache_key, new_control)
  new_control
end

.new_resource(resource_name, resource_data, control_maps) ⇒ Resource

Creates a new Resource object. If an object with the same resource name, resource data, and control maps already exists, it will be returned instead of creating a new one.

Parameters:

  • resource_name (String)

    The name of the resource.

  • resource_data (Hash)

    The data for the resource.

  • control_maps (Array)

    The control maps for the resource.

Returns:

  • (Resource)

    The new or cached Resource object.



679
680
681
682
683
684
685
686
687
688
689
690
691
# File 'lib/abide-data-processor/parser.rb', line 679

def new_resource(resource_name, resource_data, control_maps)
  cache_key = [Resource.name, resource_name, resource_data, control_maps]
  cached = cache_get(cache_key)
  return cached unless cached.nil?

  begin
    new_resource = Resource.new(resource_name, resource_data, control_maps)
  rescue ArgumentError => e
    raise ArgumentError, "Failed to create resource #{resource_name}: #{e.message}"
  end
  cache_add(cache_key, new_resource)
  new_resource
end

.parse(hiera_data, control_maps, control_configs: {}, ignore: [], only: []) ⇒ Hash

Parse Hiera data into a resource data Hash

Parameters:

  • hiera_data (Hash)

    Hiera data to parse

  • control_maps (Array)

    Control maps to use

Returns:

  • (Hash)

    Parsed resource data



19
20
21
22
23
24
25
26
27
# File 'lib/abide-data-processor/parser.rb', line 19

def self.parse(hiera_data, control_maps, control_configs: {}, ignore: [], only: [])
  ResourceDataParser.new(
    hiera_data,
    control_maps,
    control_configs: control_configs,
    ignore: ignore,
    only: only
  ).parse
end