module AbideDataProcessor::Parser
This module contains the logic for creating resource data from Hiera data.
Constants
- MAP_TYPES
- METAPARAMS
Public Class Methods
Clears the current cache. Used in testing.
# File lib/abide-data-processor/parser.rb, line 714 def clear_cache @object_cache = {} end
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. @param control_name [String] The name of the control. @param control_data [Hash] The data for the control. @param control_maps [Array] The control maps for the control. @return [Control] The new or cached Control
object.
# 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
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. @param resource_name [String] The name of the resource. @param resource_data [Hash] The data for the resource. @param control_maps [Array] The control maps for the resource. @return [Resource] The new or cached Resource
object.
# 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 into a resource data Hash @param hiera_data [Hash] Hiera data to parse @param control_maps [Array] Control
maps to use @return [Hash] Parsed resource data
# 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
Private Class Methods
Helper method to add a ProcessorObject
(or subclass of one) to the cache. @param key [Array] The key for the cache. An array comprised of the object name, object data, and control maps. @param resource [ProcessorObject] The object to add to the cache.
# File lib/abide-data-processor/parser.rb, line 724 def cache_add(key, object) object_cache[key] = object end
Helper method to retrieve a ProcessorObject
from the cache. @param key [Array] The key for the cache. An array comprised of the resource name, resource data, and control maps. @return [ProcessorObject] The object from the cache, or nil if the object doesn’t exist.
# File lib/abide-data-processor/parser.rb, line 731 def cache_get(key) object_cache.fetch(key, nil) end
Holds the object cache. If the object cache doesn’t exist, it will be created.
# File lib/abide-data-processor/parser.rb, line 736 def object_cache @object_cache ||= {} end