Class: Puppet::Pal::JsonCatalogEncoder
- Defined in:
- lib/puppet/pal/json_catalog_encoder.rb
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.
31 32 33 34 35 |
# File 'lib/puppet/pal/json_catalog_encoder.rb', line 31 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.
16 17 18 |
# File 'lib/puppet/pal/json_catalog_encoder.rb', line 16 def exclude_virtual @exclude_virtual end |
#pretty ⇒ Object (readonly)
Is the resulting Json pretty printed or not.
13 14 15 |
# File 'lib/puppet/pal/json_catalog_encoder.rb', line 13 def pretty @pretty end |
Instance Method Details
#encode ⇒ Object
Encodes the entire catalog as a rich-data Json catalog.
41 42 43 |
# File 'lib/puppet/pal/json_catalog_encoder.rb', line 41 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.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/puppet/pal/json_catalog_encoder.rb', line 51 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 |