class Google::Cloud::ResourceManager::Resource

# Resource

A container to reference an id for any resource type. A `resource` in Google Cloud Platform is a generic term for something a developer may want to interact with through an API. Some examples are an App Engine app, a Compute Engine instance, a Cloud SQL database, and so on. (See {Manager#resource}.)

@example

require "google/cloud/resource_manager"

resource_manager = Google::Cloud::ResourceManager.new
project = resource_manager.project "tokyo-rain-123"
folder = Google::Cloud::ResourceManager::Resource.new "folder", "1234"
project.parent = folder

Attributes

id[RW]

Required field for the type-specific id. This should correspond to the id used in the type-specific API's. @return [String]

type[RW]

Required field representing the resource type this id is for. At present, the valid types are: “organization” and “folder”. @return [String]

Public Class Methods

folder(id) click to toggle source

Create a Resource object with type `folder`.

@param [String] id The type-specific id. This should correspond to the

id used in the type-specific API's.

@return [Resource]

# File lib/google/cloud/resource_manager/resource.rb, line 86
def self.folder id
  new "folder", id
end
from_gapi(gapi) click to toggle source

@private Create new Resource from a Google API Client ResourceId object.

# File lib/google/cloud/resource_manager/resource.rb, line 113
def self.from_gapi gapi
  new gapi.type, gapi.id
end
new(type, id) click to toggle source

Create a Resource object.

@param [String] type The resource type this id is for. At present, the

valid types are: "organization" and "folder".

@param [String] id The type-specific id. This should correspond to the

id used in the type-specific API's.
# File lib/google/cloud/resource_manager/resource.rb, line 44
def initialize type, id
  raise ArgumentError, "type is required" if type.nil?
  raise ArgumentError, "id is required"   if id.nil?

  @type = type
  @id   = id
end
organization(id) click to toggle source

Create a Resource object with type `organization`.

@param [String] id The type-specific id. This should correspond to the

id used in the type-specific API's.

@return [Resource]

# File lib/google/cloud/resource_manager/resource.rb, line 96
def self.organization id
  new "organization", id
end

Public Instance Methods

folder?() click to toggle source

Checks if the type is `folder`. @return [Boolean]

# File lib/google/cloud/resource_manager/resource.rb, line 67
def folder?
  return false if type.nil?
  "folder".casecmp(type).zero?
end
organization?() click to toggle source

Checks if the type is `organization`. @return [Boolean]

# File lib/google/cloud/resource_manager/resource.rb, line 75
def organization?
  return false if type.nil?
  "organization".casecmp(type).zero?
end
to_gapi() click to toggle source

@private Convert the Resource to a Google API Client ResourceId object.

# File lib/google/cloud/resource_manager/resource.rb, line 103
def to_gapi
  Google::Apis::CloudresourcemanagerV1::ResourceId.new(
    type: type,
    id: id
  )
end