|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative 'common' |
| 4 | +require_relative '../../catalog' |
| 5 | + |
| 6 | +require 'ostruct' |
| 7 | + |
| 8 | +module OctocatalogDiff |
| 9 | + module API |
| 10 | + module V1 |
| 11 | + # This is a wrapper class around OctocatalogDiff::Catalog. This contains the methods we |
| 12 | + # are choosing to expose, and will be a compatibility layer should underlying methods |
| 13 | + # change in the future. The raw object will be available as `#raw` but this is not |
| 14 | + # guaranteed to be stable. |
| 15 | + class Catalog |
| 16 | + attr_reader :raw |
| 17 | + |
| 18 | + # Constructor: Accepts a raw OctocatalogDiff::Catalog object and stores it. |
| 19 | + # @param raw [OctocatalogDiff::Catalog] Catalog object |
| 20 | + def initialize(raw) |
| 21 | + unless raw.is_a?(OctocatalogDiff::Catalog) |
| 22 | + raise ArgumentError, 'OctocatalogDiff::API::V1::Catalog#initialize expects OctocatalogDiff::Catalog argument' |
| 23 | + end |
| 24 | + @raw = raw |
| 25 | + end |
| 26 | + |
| 27 | + # Public: Get the builder for the catalog |
| 28 | + # @return [String] Class of backend used |
| 29 | + def builder |
| 30 | + @raw.builder |
| 31 | + end |
| 32 | + |
| 33 | + # Public: Get the JSON for the catalog |
| 34 | + # @return [String] Catalog JSON |
| 35 | + def catalog_json |
| 36 | + @raw.catalog_json |
| 37 | + end |
| 38 | + |
| 39 | + # Public: Get the compilation directory |
| 40 | + # @return [String] Compilation directory |
| 41 | + def compilation_dir |
| 42 | + @raw.compilation_dir |
| 43 | + end |
| 44 | + |
| 45 | + # Public: Get the error message |
| 46 | + # @return [String] Error message, or nil if no error |
| 47 | + def error_message |
| 48 | + @raw.error_message |
| 49 | + end |
| 50 | + |
| 51 | + # Public: Get the Puppet version used to compile the catalog |
| 52 | + # @return [String] Puppet version |
| 53 | + def puppet_version |
| 54 | + @raw.puppet_version |
| 55 | + end |
| 56 | + |
| 57 | + # Public: Get a specific resource identified by type and title. |
| 58 | + # This is intended for use when a O(1) lookup is required. |
| 59 | + # @param :type [String] Type of resource |
| 60 | + # @param :title [String] Title of resource |
| 61 | + # @return [Hash] Resource item |
| 62 | + def resource(opts = {}) |
| 63 | + @raw.resource(opts) |
| 64 | + end |
| 65 | + |
| 66 | + # Public: Get the resources in the catalog |
| 67 | + # @return [Array] Resource array |
| 68 | + def resources |
| 69 | + @raw.resources |
| 70 | + end |
| 71 | + |
| 72 | + # Public: Determine if the catalog build was successful. |
| 73 | + # @return [Boolean] Whether the catalog is valid |
| 74 | + def valid? |
| 75 | + @raw.valid? |
| 76 | + end |
| 77 | + end |
| 78 | + end |
| 79 | + end |
| 80 | +end |
0 commit comments