Sha256: ca3a3ac7aa975edf8dfa3a6d7e0c0c7efeaa9e7955dc6fd820f0310fe6448909

Contents?: true

Size: 1.12 KB

Versions: 26

Compression:

Stored size: 1.12 KB

Contents

require "fog/core/collection"
require "fog/google/models/sql/instance"

module Fog
  module Google
    class SQL
      class Instances < Fog::Collection
        model Fog::Google::SQL::Instance

        ##
        # Lists all instance
        #
        # @return [Array<Fog::Google::SQL::Instance>] List of instance resources
        def all
          data = service.list_instances.to_h[:items] || []
          load(data)
        end

        ##
        # Retrieves an instance
        #
        # @param [String] instance_id Instance ID
        # @return [Fog::Google::SQL::Instance] Instance resource
        def get(instance_id)
          instance = service.get_instance(instance_id).to_h
          # XXX if we pass `nil` to get() it returns empty DB object with
          # kind set to "sql#instancesList"
          # see https://github.com/google/google-api-ruby-client/issues/699
          if instance[:kind].eql?("sql#instance")
            new(instance)
          end
        rescue ::Google::Apis::ClientError => e
          raise e unless e.status_code == 404 || e.status_code == 403
          nil
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
fog-google-1.24.1 lib/fog/google/models/sql/instances.rb
fog-google-1.24.0 lib/fog/google/models/sql/instances.rb
fog-google-1.23.0 lib/fog/google/models/sql/instances.rb
fog-google-1.22.0 lib/fog/google/models/sql/instances.rb
fog-google-1.21.1 lib/fog/google/models/sql/instances.rb
fog-google-1.21.0 lib/fog/google/models/sql/instances.rb
fog-google-1.20.0 lib/fog/google/models/sql/instances.rb
fog-google-1.19.0 lib/fog/google/models/sql/instances.rb
fog-google-1.18.0 lib/fog/google/models/sql/instances.rb
fog-google-1.17.0 lib/fog/google/models/sql/instances.rb
fog-google-1.16.1 lib/fog/google/models/sql/instances.rb
fog-google-1.16.0 lib/fog/google/models/sql/instances.rb
fog-google-1.15.0 lib/fog/google/models/sql/instances.rb
fog-google-1.14.0 lib/fog/google/models/sql/instances.rb
gitlab-fog-google-1.14.0 lib/fog/google/models/sql/instances.rb
fog-google-1.13.0 lib/fog/google/models/sql/instances.rb
gitlab-fog-google-1.13.0 lib/fog/google/models/sql/instances.rb
fog-google-1.12.1 lib/fog/google/models/sql/instances.rb
fog-google-1.12.0 lib/fog/google/models/sql/instances.rb
fog-google-1.11.0 lib/fog/google/models/sql/instances.rb