Class: Puppet::Pal::JsonCatalogEncoder
Overview
The JsonCatalogEncoder is a wrapper around a catalog produced by the Pal::CatalogCompiler.with_json_encoding method. It allows encoding the entire catalog or an individual resource as Rich Data Json.
Instance Attribute Summary collapse
-
#exclude_virtual ⇒ Object
readonly
Should unrealized virtual resources be included in the result or not.
-
#pretty ⇒ Object
readonly
Is the resulting Json pretty printed or not.
Instance Method Summary collapse
-
#encode ⇒ Object
Encodes the entire catalog as a rich-data Json catalog.
-
#encode_resource(type, title) ⇒ String
Returns one particular resource as a Json string, or returns nil if resource was not found.
-
#initialize(catalog, pretty: true, exclude_virtual: true) ⇒ JsonCatalogEncoder
constructor
private
Do not instantiate this class directly! Use the ‘Pal::CatalogCompiler#with_json_encoding` method instead.
Constructor Details
#initialize(catalog, pretty: true, exclude_virtual: true) ⇒ JsonCatalogEncoder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Do not instantiate this class directly! Use the ‘Pal::CatalogCompiler#with_json_encoding` method instead.
395 396 397 398 399 |
# File 'lib/puppet_pal.rb', line 395 def initialize(catalog, pretty: true, exclude_virtual: true) @catalog = catalog @pretty = pretty @exclude_virtual = exclude_virtual end |
Instance Attribute Details
#exclude_virtual ⇒ Object (readonly)
Should unrealized virtual resources be included in the result or not.
380 381 382 |
# File 'lib/puppet_pal.rb', line 380 def exclude_virtual @exclude_virtual end |
#pretty ⇒ Object (readonly)
Is the resulting Json pretty printed or not.
377 378 379 |
# File 'lib/puppet_pal.rb', line 377 def pretty @pretty end |
Instance Method Details
#encode ⇒ Object
Encodes the entire catalog as a rich-data Json catalog.
405 406 407 |
# File 'lib/puppet_pal.rb', line 405 def encode possibly_filtered_catalog.to_json(:pretty => pretty) end |
#encode_resource(type, title) ⇒ String
Returns one particular resource as a Json string, or returns nil if resource was not found.
415 416 417 418 419 420 421 422 423 424 |
# File 'lib/puppet_pal.rb', line 415 def encode_resource(type, title) # Ensure that both type and title are given since the underlying API will do mysterious things # if 'title' is nil. (Other assertions are made by the catalog when looking up the resource). # # TRANSLATORS 'type' and 'title' are internal parameter names - do not translate raise ArgumentError, _("Both type and title must be given") if type.nil? or title.nil? r = possibly_filtered_catalog.resource(type, title) return nil if r.nil? r.to_data_hash.to_json(:pretty => pretty) end |