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::Bucket::Lifecycle::Rule.

## Bucket Lifecycle Rule

Represents an Object Lifecycle Management rule for a bucket. The
action for the rule will be taken when its conditions are met.
Accessed via [Google::Cloud::Storage::Bucket#lifecycle](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_lifecycle_instance_ "Google::Cloud::Storage::Bucket#lifecycle (method)").

## Inherits

- Object

## Examples

Retrieving a bucket's lifecycle management rules.

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

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

bucket.lifecycle.size #=> 2
rule = bucket.lifecycle.first
rule.action #=> "SetStorageClass"
rule.storage_class #=> "COLDLINE"
rule.age #=> 10
rule.matches_storage_class #=> ["STANDARD", "NEARLINE"]
rule.matches_prefix #=> ["myprefix/foo"]
rule.matches_suffix #=> [".jpg", ".png"]
```

Updating the bucket's lifecycle rules in a block.

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

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

bucket.update do |b|
  b.lifecycle do |l|
    # Remove the last rule from the array
    l.pop
    # Remove rules with the given condition
    l.delete_if do |r|
      r.matches_storage_class.include? "NEARLINE"
    end
    # Update rules
    l.each do |r|
      r.age = 90 if r.action == "Delete"
    end
    # Add a rule
    l.add_set_storage_class_rule "COLDLINE", age: 10
  end
end
```

## Methods

### #action

```ruby
def action() -> String
```
The type of action taken when the rule's
conditions are met. Currently, only `Delete` and `SetStorageClass`
are supported.
**Returns**

- (String) --- the current value of action

### #action=

```ruby
def action=(value) -> String
```
The type of action taken when the rule's
conditions are met. Currently, only `Delete` and `SetStorageClass`
are supported.
**Parameter**

- **value** (String) --- the newly set value
**Returns**

- (String) --- the newly set value

### #age

```ruby
def age() -> Integer
```
The age of a file (in days). This condition is
satisfied when a file reaches the specified age.
**Returns**

- (Integer) --- the current value of age

### #age=

```ruby
def age=(value) -> Integer
```
The age of a file (in days). This condition is
satisfied when a file reaches the specified age.
**Parameter**

- **value** (Integer) --- the newly set value
**Returns**

- (Integer) --- the newly set value

### #created_before

```ruby
def created_before() -> String, Date, nil
```
A date in RFC 3339 format with
only the date part (for instance, "2013-01-15"). This condition is
satisfied when a file is created before midnight of the specified
date in UTC. When returned by the service, a non-empty value will
always be a Date object.
**Returns**

- (String, Date, nil) --- the current value of created_before

### #created_before=

```ruby
def created_before=(value) -> String, Date, nil
```
A date in RFC 3339 format with
only the date part (for instance, "2013-01-15"). This condition is
satisfied when a file is created before midnight of the specified
date in UTC. When returned by the service, a non-empty value will
always be a Date object.
**Parameter**

- **value** (String, Date, nil) --- the newly set value
**Returns**

- (String, Date, nil) --- the newly set value

### #custom_time_before

```ruby
def custom_time_before() -> String, Date, nil
```
A date in RFC 3339 format with
only the date part (for instance, "2013-01-15"). This condition is
satisfied when the custom time on an object is before this date in UTC.
**Returns**

- (String, Date, nil) --- the current value of custom_time_before

### #custom_time_before=

```ruby
def custom_time_before=(value) -> String, Date, nil
```
A date in RFC 3339 format with
only the date part (for instance, "2013-01-15"). This condition is
satisfied when the custom time on an object is before this date in UTC.
**Parameter**

- **value** (String, Date, nil) --- the newly set value
**Returns**

- (String, Date, nil) --- the newly set value

### #days_since_custom_time

```ruby
def days_since_custom_time() -> Integer, nil
```
Represents the number of
days elapsed since the user-specified timestamp set on an object.
The condition is satisfied if the days elapsed is at least this
number. If no custom timestamp is specified on an object, the
condition does not apply.
**Returns**

- (Integer, nil) --- the current value of days_since_custom_time

### #days_since_custom_time=

```ruby
def days_since_custom_time=(value) -> Integer, nil
```
Represents the number of
days elapsed since the user-specified timestamp set on an object.
The condition is satisfied if the days elapsed is at least this
number. If no custom timestamp is specified on an object, the
condition does not apply.
**Parameter**

- **value** (Integer, nil) --- the newly set value
**Returns**

- (Integer, nil) --- the newly set value

### #days_since_noncurrent_time

```ruby
def days_since_noncurrent_time() -> Integer
```
Represents the number of
days elapsed since the noncurrent timestamp of an object. The
condition is satisfied if the days elapsed is at least this number.
The value of the field must be a nonnegative integer. If it's zero,
the object version will become eligible for Lifecycle action as
soon as it becomes noncurrent. Relevant only for versioning-enabled
buckets. (See [Google::Cloud::Storage::Bucket#versioning?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_versioning__instance_ "Google::Cloud::Storage::Bucket#versioning? (method)"))
**Returns**

- (Integer) --- the current value of days_since_noncurrent_time

### #days_since_noncurrent_time=

```ruby
def days_since_noncurrent_time=(value) -> Integer
```
Represents the number of
days elapsed since the noncurrent timestamp of an object. The
condition is satisfied if the days elapsed is at least this number.
The value of the field must be a nonnegative integer. If it's zero,
the object version will become eligible for Lifecycle action as
soon as it becomes noncurrent. Relevant only for versioning-enabled
buckets. (See [Google::Cloud::Storage::Bucket#versioning?](https://docs.cloud.google.com/ruby/docs/reference/google-cloud-storage/latest/Google-Cloud-Storage-Bucket.md.txt#Google__Cloud__Storage__Bucket_versioning__instance_ "Google::Cloud::Storage::Bucket#versioning? (method)"))
**Parameter**

- **value** (Integer) --- the newly set value
**Returns**

- (Integer) --- the newly set value

### #is_live

```ruby
def is_live() -> Boolean
```
Relevant only for versioned files. If the
value is `true`, this condition matches live files; if the value
is `false`, it matches archived files.
**Returns**

- (Boolean) --- the current value of is_live

### #is_live=

```ruby
def is_live=(value) -> Boolean
```
Relevant only for versioned files. If the
value is `true`, this condition matches live files; if the value
is `false`, it matches archived files.
**Parameter**

- **value** (Boolean) --- the newly set value
**Returns**

- (Boolean) --- the newly set value

### #matches_prefix

```ruby
def matches_prefix()
```
Returns the value of attribute matches_prefix.

### #matches_prefix=

```ruby
def matches_prefix=(value)
```
Sets the attribute matches_prefix

### #matches_storage_class

```ruby
def matches_storage_class() -> Array<String>
```
Files having any of the
storage classes specified by this condition will be matched.
Values include `STANDARD`, `NEARLINE`, `COLDLINE`, and `ARCHIVE`.
`REGIONAL`, `MULTI_REGIONAL`, and `DURABLE_REDUCED_AVAILABILITY`
are supported as legacy storage classes.
**Returns**

- (Array\<String\>) --- the current value of matches_storage_class

### #matches_storage_class=

```ruby
def matches_storage_class=(value) -> Array<String>
```
Files having any of the
storage classes specified by this condition will be matched.
Values include `STANDARD`, `NEARLINE`, `COLDLINE`, and `ARCHIVE`.
`REGIONAL`, `MULTI_REGIONAL`, and `DURABLE_REDUCED_AVAILABILITY`
are supported as legacy storage classes.
**Parameter**

- **value** (Array\<String\>) --- the newly set value
**Returns**

- (Array\<String\>) --- the newly set value

### #matches_suffix

```ruby
def matches_suffix()
```
Returns the value of attribute matches_suffix.

### #matches_suffix=

```ruby
def matches_suffix=(value)
```
Sets the attribute matches_suffix

### #noncurrent_time_before

```ruby
def noncurrent_time_before() -> String, Date, nil
```
A date in RFC 3339 format
with only the date part (for instance, "2013-01-15"). This condition
is satisfied when the noncurrent time on an object is before this
date in UTC. This condition is relevant only for versioned objects.
When returned by the service, a non-empty value will always be a
Date object.
**Returns**

- (String, Date, nil) --- the current value of noncurrent_time_before

### #noncurrent_time_before=

```ruby
def noncurrent_time_before=(value) -> String, Date, nil
```
A date in RFC 3339 format
with only the date part (for instance, "2013-01-15"). This condition
is satisfied when the noncurrent time on an object is before this
date in UTC. This condition is relevant only for versioned objects.
When returned by the service, a non-empty value will always be a
Date object.
**Parameter**

- **value** (String, Date, nil) --- the newly set value
**Returns**

- (String, Date, nil) --- the newly set value

### #num_newer_versions

```ruby
def num_newer_versions() -> Integer
```
Relevant only for versioned
files. If the value is N, this condition is satisfied when there
are at least N versions (including the live version) newer than
this version of the file.
**Returns**

- (Integer) --- the current value of num_newer_versions

### #num_newer_versions=

```ruby
def num_newer_versions=(value) -> Integer
```
Relevant only for versioned
files. If the value is N, this condition is satisfied when there
are at least N versions (including the live version) newer than
this version of the file.
**Parameter**

- **value** (Integer) --- the newly set value
**Returns**

- (Integer) --- the newly set value

### #storage_class

```ruby
def storage_class() -> String
```
The target storage class for the
action. Required only if the action is `SetStorageClass`.
**Returns**

- (String) --- the current value of storage_class

### #storage_class=

```ruby
def storage_class=(value) -> String
```
The target storage class for the
action. Required only if the action is `SetStorageClass`.
**Parameter**

- **value** (String) --- the newly set value
**Returns**

- (String) --- the newly set value