Class: SiteMaps::Adapters::AwsSdk::Storage
- Inherits:
-
Object
- Object
- SiteMaps::Adapters::AwsSdk::Storage
- Defined in:
- lib/site_maps/adapters/aws_sdk/storage.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #delete(location) ⇒ Object
-
#initialize(config) ⇒ Storage
constructor
A new instance of Storage.
- #read(location) ⇒ Object
- #upload(location, **options) ⇒ Object
Constructor Details
#initialize(config) ⇒ Storage
Returns a new instance of Storage.
6 7 8 |
# File 'lib/site_maps/adapters/aws_sdk/storage.rb', line 6 def initialize(config) @config = config end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/site_maps/adapters/aws_sdk/storage.rb', line 4 def config @config end |
Instance Method Details
#delete(location) ⇒ Object
35 36 37 38 39 |
# File 'lib/site_maps/adapters/aws_sdk/storage.rb', line 35 def delete(location) object(location.remote_path).delete rescue Aws::S3::Errors::NoSuchKey raise SiteMaps::FileNotFoundError, "File not found: #{location.remote_path}" end |
#read(location) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/site_maps/adapters/aws_sdk/storage.rb', line 21 def read(location) obj = object(location.remote_path).get = { content_type: obj.content_type } if (raw = obj.["given-last-modified"]) && (time = Time.parse(raw)) [:last_modified] = time end [obj.body.read, ] rescue Aws::S3::Errors::NoSuchKey raise SiteMaps::FileNotFoundError, "File not found: #{location.remote_path}" end |
#upload(location, **options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/site_maps/adapters/aws_sdk/storage.rb', line 10 def upload(location, **) [:acl] ||= config.acl if config.acl [:cache_control] ||= config.cache_control if config.cache_control [:content_type] ||= location.gzip? ? "application/gzip" : "application/xml" lastmod = .delete(:last_modified) || Time.now [:metadata] ||= {} [:metadata]["given-last-modified"] = lastmod.utc.strftime("%Y-%m-%dT%H:%M:%S%:z") obj = object(location.remote_path) obj.upload_file(location.path, **) end |