Class: Gcloud::Storage::Bucket::Cors
- Inherits:
-
Array
- Object
- Array
- Gcloud::Storage::Bucket::Cors
- Defined in:
- lib/gcloud/storage/bucket/cors.rb
Overview
# Bucket Cors
A special-case Array for managing the website CORS rules for a bucket. Accessed via a block argument to Project#create_bucket, #cors, or #update.
Instance Method Summary collapse
-
#add_rule(origin, methods, headers: nil, max_age: nil) ⇒ Object
Add a CORS rule to the CORS rules for a bucket.
- #changed? ⇒ Boolean
-
#initialize(cors = []) ⇒ Cors
constructor
Initialize a new CORS rules builder with existing CORS rules, if any.
Constructor Details
#initialize(cors = []) ⇒ Cors
Initialize a new CORS rules builder with existing CORS rules, if any.
53 54 55 56 |
# File 'lib/gcloud/storage/bucket/cors.rb', line 53 def initialize cors = [] super cors.dup @original = cors.dup end |
Instance Method Details
#add_rule(origin, methods, headers: nil, max_age: nil) ⇒ Object
Add a CORS rule to the CORS rules for a bucket. Accepts options for setting preflight response headers. Preflight requests and responses are required if the request method and headers are not both [simple methods](www.w3.org/TR/cors/#simple-method) and [simple headers](www.w3.org/TR/cors/#simple-header).
100 101 102 103 104 105 |
# File 'lib/gcloud/storage/bucket/cors.rb', line 100 def add_rule origin, methods, headers: nil, max_age: nil rule = { "origin" => Array(origin), "method" => Array(methods) } rule["responseHeader"] = Array(headers) || [] rule["maxAgeSeconds"] = max_age || 1800 push rule end |
#changed? ⇒ Boolean
59 60 61 |
# File 'lib/gcloud/storage/bucket/cors.rb', line 59 def changed? @original != self end |