Class: OctocatalogDiff::Catalog::JSON
- Inherits:
-
Object
- Object
- OctocatalogDiff::Catalog::JSON
- Defined in:
- lib/octocatalog-diff/catalog/json.rb
Overview
Represents a Puppet catalog that is read in directly from a JSON file.
Instance Attribute Summary collapse
-
#catalog ⇒ Object
readonly
Returns the value of attribute catalog.
-
#catalog_json ⇒ Object
readonly
Returns the value of attribute catalog_json.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#node ⇒ Object
Returns the value of attribute node.
Instance Method Summary collapse
-
#initialize(options) ⇒ JSON
constructor
Constructor.
Constructor Details
#initialize(options) ⇒ JSON
Constructor
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/octocatalog-diff/catalog/json.rb', line 15 def initialize() raise ArgumentError, 'Usage: OctocatalogDiff::Catalog::JSON.initialize(options_hash)' unless .is_a?(Hash) raise ArgumentError, "Must supply :json as string in options: #{[:json].class}" unless [:json].is_a?(String) @catalog_json = [:json] begin @catalog = ::JSON.parse(@catalog_json) @error_message = nil @node ||= @catalog['name'] if @catalog.key?('name') # Puppet 4.x @node ||= @catalog['data']['name'] if @catalog.key?('data') && @catalog['data'].is_a?(Hash) # Puppet 3.x rescue ::JSON::ParserError => exc @error_message = "Catalog JSON input failed to parse: #{exc.}" @catalog = nil @catalog_json = nil end end |
Instance Attribute Details
#catalog ⇒ Object (readonly)
Returns the value of attribute catalog.
10 11 12 |
# File 'lib/octocatalog-diff/catalog/json.rb', line 10 def catalog @catalog end |
#catalog_json ⇒ Object (readonly)
Returns the value of attribute catalog_json.
10 11 12 |
# File 'lib/octocatalog-diff/catalog/json.rb', line 10 def catalog_json @catalog_json end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
10 11 12 |
# File 'lib/octocatalog-diff/catalog/json.rb', line 10 def @error_message end |
#node ⇒ Object
Returns the value of attribute node.
9 10 11 |
# File 'lib/octocatalog-diff/catalog/json.rb', line 9 def node @node end |