Class: Google::Cloud::ResourceManager::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/resource_manager/resource.rb

Overview

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.)

Examples:

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, id) ⇒ Resource

Create a Resource object.

Parameters:

  • type (String)

    The resource type this id is for. At present, the valid types are: "organization" and "folder".

  • id (String)

    The type-specific id. This should correspond to the id used in the type-specific API's.

Raises:

  • (ArgumentError)


44
45
46
47
48
49
50
# 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

Instance Attribute Details

#idString

Required field for the type-specific id. This should correspond to the id used in the type-specific API's.

Returns:

  • (String)


62
63
64
# File 'lib/google/cloud/resource_manager/resource.rb', line 62

def id
  @id
end

#typeString

Required field representing the resource type this id is for. At present, the valid types are: "organization" and "folder".

Returns:

  • (String)


56
57
58
# File 'lib/google/cloud/resource_manager/resource.rb', line 56

def type
  @type
end

Class Method Details

.folder(id) ⇒ Resource

Create a Resource object with type folder.

Parameters:

  • id (String)

    The type-specific id. This should correspond to the id used in the type-specific API's.

Returns:



86
87
88
# File 'lib/google/cloud/resource_manager/resource.rb', line 86

def self.folder id
  new "folder", id
end

.organization(id) ⇒ Resource

Create a Resource object with type organization.

Parameters:

  • id (String)

    The type-specific id. This should correspond to the id used in the type-specific API's.

Returns:



96
97
98
# File 'lib/google/cloud/resource_manager/resource.rb', line 96

def self.organization id
  new "organization", id
end

Instance Method Details

#folder?Boolean

Checks if the type is folder.

Returns:

  • (Boolean)


67
68
69
70
# File 'lib/google/cloud/resource_manager/resource.rb', line 67

def folder?
  return false if type.nil?
  "folder".casecmp(type).zero?
end

#organization?Boolean

Checks if the type is organization.

Returns:

  • (Boolean)


75
76
77
78
# File 'lib/google/cloud/resource_manager/resource.rb', line 75

def organization?
  return false if type.nil?
  "organization".casecmp(type).zero?
end