Sha256: 7c94a4b034f7ecb4cb3017a667eed0fb0a98375bf7105a3678e97f0dbe4c067a
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
require "kvmultiplex/provider" require "json" require "aws-sdk-s3" module KVMultiplex module Providers class S3 < KVMultiplex::Provider def initialize(bucket_name:, key_prefix:, resource_client: nil) raise "bucket_name must be a String." unless bucket_name.is_a?(String) raise "key_prefix must be a String." unless key_prefix.is_a?(String) resource_client ||= Aws::S3::Resource.new raise "resource_client must be an Aws::S3::Resource." unless client.is_a?(Aws::S3::Resource) @bucket_name = bucket_name @bucket = resource_client.bucket(@bucket_name) raise "bucket '#{bucket_name}' doesn't exist." unless @bucket.exists? @key_prefix = key_prefix @resource_client = resource_client end def get(subkey, _full_key) object = locate_object(subkey) object.exists? ? JSON.parse(object.get.body.read) : nil end def set(subkey, _full_key, value) locate_object(subkey).put(body: value.to_json) end private def locate_object(subkey) @bucket.object(subkey.join("/")) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kvmultiplex-s3-0.1.4 | lib/kvmultiplex/providers/s3.rb |