1.62.2 (latest) 1.62.1 1.61.0 1.60.0 1.59.0 1.58.0 1.57.1 1.56.0 1.55.0 1.54.0 1.53.0 1.52.0 1.51.0 1.50.0 1.49.0 1.48.1 1.47.0 1.46.0 1.45.0 1.44.0 1.43.0 1.42.0 1.41.0 1.40.0 1.39.0 1.38.0 1.37.0 1.36.2 1.35.0 Reference documentation and code samples for the Cloud Storage API class Google::Cloud::Storage::Policy::Bindings.

## Bindings

Enumerable object for managing Cloud IAM bindings associated with
a bucket.

## Inherits

- Object

## Includes

- Enumerable

## Example

Updating a Policy from version 1 to version 3:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access = true

bucket.policy requested_policy_version: 3 do |p|
  p.version # the value is 1
  p.version = 3 # Must be explicitly set to opt-in to support for conditions.

  expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
  p.bindings.insert({
                      role: "roles/storage.admin",
                      members: ["user:owner@example.com"],
                      condition: {
                        title: "my-condition",
                        description: "description of condition",
                        expression: expr
                      }
                    })
end
```

## Methods

### #each

```ruby
def each() { |binding| ... } -> Enumerator
```
Calls the block once for each binding in the collection, passing
a [Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt "Google::Cloud::Storage::Policy::Binding (class)") object as parameter. A
[Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt "Google::Cloud::Storage::Policy::Binding (class)") object is passed even
when the arguments to [#insert](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings.md.txt#Google__Cloud__Storage__Policy__Bindings_insert_instance_ "Google::Cloud::Storage::Policy::Bindings#insert (method)") were hash objects.


<br />

If no block is given, an enumerator is returned instead.
**Yields**

- (binding) --- A binding in this bindings collection.
**Yield Parameter**

- **binding** ([Google::Cloud::Storage::Policy::Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt)) --- A binding object, even when the arguments to [#insert](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings.md.txt#Google__Cloud__Storage__Policy__Bindings_insert_instance_ "Google::Cloud::Storage::Policy::Bindings#insert (method)") were hash objects.
**Returns**

- (Enumerator)
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

policy = bucket.policy requested_policy_version: 3
policy.bindings.each do |binding|
  puts binding.role
end
```

### #insert

```ruby
def insert(*bindings) -> Bindings
```
Adds a binding or bindings to the collection. The arguments may be
[Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt "Google::Cloud::Storage::Policy::Binding (class)") objects or equivalent hash
objects that will be implicitly coerced to binding objects.
**Parameter**

- **bindings** ([Google::Cloud::Storage::Policy::Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt), Hash) --- One or more bindings to be added to the policy owning the collection. The arguments may be [Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt "Google::Cloud::Storage::Policy::Binding (class)") objects or equivalent hash objects that will be implicitly coerced to binding objects.
**Returns**

- ([Bindings](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings.md.txt)) --- `self` for chaining.
**Example**

Updating a Policy from version 1 to version 3:

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.uniform_bucket_level_access = true

bucket.policy requested_policy_version: 3 do |p|
  p.version # the value is 1
  p.version = 3 # Must be explicitly set to opt-in to support for conditions.

  expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
  p.bindings.insert({
                      role: "roles/storage.admin",
                      members: ["user:owner@example.com"],
                      condition: {
                        title: "my-condition",
                        description: "description of condition",
                        expression: expr
                      }
                    })
end
```

### #remove

```ruby
def remove(*bindings) -> Bindings
```
Deletes the binding or bindings from the collection that are equal to
the arguments. The specification arguments may be
[Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt "Google::Cloud::Storage::Policy::Binding (class)") objects or equivalent hash
objects that will be implicitly coerced to binding objects.
**Parameter**

- **bindings** ([Google::Cloud::Storage::Policy::Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt), Hash) --- One or more specifications for bindings to be removed from the collection. The arguments may be [Binding](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Binding.md.txt "Google::Cloud::Storage::Policy::Binding (class)") objects or equivalent hash objects that will be implicitly coerced to binding objects.
**Returns**

- ([Bindings](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Policy-Bindings.md.txt)) --- `self` for chaining.
**Example**

```ruby
require "google/cloud/storage"

storage = Google::Cloud::Storage.new
bucket = storage.bucket "my-bucket"

bucket.policy requested_policy_version: 3 do |p|
  expr = "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")"
  p.bindings.remove({
                      role: "roles/storage.admin",
                      members: ["user:owner@example.com"],
                      condition: {
                        title: "my-condition",
                        description: "description of condition",
                        expression: expr
                      }
                    })
end
```