Sha256: a6cefaf281c0c0ecd502035e9db75e66b1289c8b3ea5d3f64bbb6d8ddd9cbf8f

Contents?: true

Size: 1.02 KB

Versions: 23

Compression:

Stored size: 1.02 KB

Contents

module Unimatrix

  class BlueprintOperation < Unimatrix::Operation

    @@blueprints = {}

    def initialize( realm_uuid, options = {} )
      @realm_uuid = realm_uuid
      super( "/realms/#{ realm_uuid }/blueprints", options )
    end

    def read
      @@blueprints[ @realm_uuid ] ||= begin
        blueprints = []

        offset = 0
        segment_count = 10
        total = nil
        errors = nil

        while total.nil? || offset < total
          operation = self.offset( offset ).include( 'blueprint_attributes' )

          operation.read do | resources, response |

            if !response.body[ 'errors' ].nil?
              errors = response.body[ 'errors' ]
              break
            end

            offset += segment_count
            total = response.body[ '$this' ][ 'unlimited_count' ]

            blueprints += resources
          end

          raise "Error requesting blueprints for realm #{ @realm_uuid }. Error: #{ errors }"  if !errors.nil?
        end

        blueprints
      end
    end

  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
unimatrix-2.5.0 lib/unimatrix/blueprint_operation.rb
unimatrix-2.4.2 lib/unimatrix/blueprint_operation.rb
unimatrix-2.3.1 lib/unimatrix/blueprint_operation.rb