Class: Puppet::Pops::Serialization::ToStringifiedConverter

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

Overview

Class that can process an arbitrary object into a value that is assignable to `Data` and where contents is converted from rich data to one of:

  • Numeric (Integer, Float)

  • Boolean

  • Undef (nil)

  • String

  • Array

  • Hash

The conversion is lossy - the result cannot be deserialized to produce the original data types. All rich values are transformed to strings.. Hashes with rich keys are transformed to use string representation of such keys.

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_boolean?, #is_parameter_of_resource?, #is_true?, #optionally_fail, #resource_to_ptype, #runtime_issue, #set_match_data, #set_scope_nesting_level, #set_variable, #variable_bound?, #variable_exists?

Constructor Details

#initialize(options = EMPTY_HASH) ⇒ ToStringifiedConverter

Creates a new instance of the processor

Options Hash (options):

  • :message_prefix (String)

    String to prepend to path in warnings and errors


39
40
41
42
# File 'lib/puppet/pops/serialization/to_stringified_converter.rb', line 39

def initialize(options = EMPTY_HASH)
  @message_prefix = options[:message_prefix]
  @semantic = options[:semantic]
end

Class Method Details

.convert(value, options = EMPTY_HASH) ⇒ Data

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

Options Hash (options):

  • :message_prefix (String)

    String to prepend to in warnings and errors

  • :semantic (String)

    object (AST) to pass to the issue reporter


30
31
32
# File 'lib/puppet/pops/serialization/to_stringified_converter.rb', line 30

def self.convert(value, options = EMPTY_HASH)
  new(options).convert(value)
end

Instance Method Details

#convert(value) ⇒ Data

Converts the given value


50
51
52
53
54
# File 'lib/puppet/pops/serialization/to_stringified_converter.rb', line 50

def convert(value)
  @path = []
  @values = {}
  to_data(value)
end