Class: Puppet::Pops::Serialization::ToDataConverter

Inherits:
Object
  • Object
show all
Includes:
Evaluator::Runtime3Support
Defined in:
lib/puppet/pops/serialization/to_data_converter.rb

Overview

Class that can process an arbitrary object into a value that is assignable to ‘Data`.

Constant Summary

Constants included from Evaluator::Runtime3Support

Evaluator::Runtime3Support::NAME_SPACE_SEPARATOR

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Evaluator::Runtime3Support

#add_relationship, #call_function, #capitalize_qualified_name, #coerce_numeric, #create_local_scope_from, #create_match_scope_from, #create_resource_defaults, #create_resource_overrides, #create_resource_parameter, #create_resources, #diagnostic_producer, #external_call_function, #extract_file_line, #fail, #find_resource, #get_resource_parameter_value, #get_scope_nesting_level, #get_variable_value, #is_parameter_of_resource?, #is_true?, #optionally_fail, #runtime_issue, #set_match_data, #set_scope_nesting_level, #set_variable, #variable_bound?, #variable_exists?

Constructor Details

#initialize(options = EMPTY_HASH) ⇒ ToDataConverter

Create a new instance of the processor

Parameters:

  • options (Symbol => Object) (defaults to: EMPTY_HASH)

    options hash

  • semantic (Hash)

    a customizable set of options

Options Hash (options):

  • :rich_data (Boolean)

    ‘true` if rich data is enabled

  • :local_references (Boolean)

    use local references instead of duplicating complex entries

  • :type_by_reference (Boolean)

    ‘true` if Object types are converted to references rather than embedded.

  • :symbol_as_string (Boolean)

    ‘true` if Symbols should be converted to strings (with type loss)

  • :message_prefix (String)

    String to prepend to path in warnings and errors

 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
# File 'lib/puppet/pops/serialization/to_data_converter.rb', line 36 def initialize(options = EMPTY_HASH) @type_by_reference = options[:type_by_reference] @type_by_reference = true if @type_by_reference.nil? @local_reference = options[:local_reference] @local_reference = true if @local_reference.nil? @symbol_as_string = options[:symbol_as_string] @symbol_as_string = false if @symbol_as_string.nil? @rich_data = options[:rich_data] @rich_data = false if @rich_data.nil? @message_prefix = options[:message_prefix] @semantic = options[:semantic] end

Class Method Details

.convert(value, options = EMPTY_HASH) ⇒ Data

Convert the given value according to the given options and return the result of the conversion

Parameters:

  • value (Object)

    the value to convert

  • options (Symbol => <Boolean,String>) (defaults to: EMPTY_HASH)

    options hash

Options Hash (options):

  • :rich_data (Boolean)

    ‘true` if rich data is enabled

  • :local_reference (Boolean)

    use local references instead of duplicating complex entries

  • :type_by_reference (Boolean)

    ‘true` if Object types are converted to references rather than embedded.

  • :symbol_as_string (Boolean)

    ‘true` if Symbols should be converted to strings (with type loss)

  • :message_prefix (String)

    String to prepend to in warnings and errors

Returns:

  • (Data)

    the processed result. An object assignable to ‘Data`.

 23 24 25
# File 'lib/puppet/pops/serialization/to_data_converter.rb', line 23 def self.convert(value, options = EMPTY_HASH) new(options).convert(value) end

Instance Method Details

#convert(value) ⇒ Data

Convert the given value

Parameters:

  • value (Object)

    the value to convert

Returns:

  • (Data)

    the processed result. An object assignable to ‘Data`.

 59 60 61 62 63
# File 'lib/puppet/pops/serialization/to_data_converter.rb', line 59 def convert(value) @path = [] @values = {} to_data(value) end