Class: HLS::Storage::S3

Inherits:
Object
  • Object
show all
Defined in:
lib/hls/storage.rb

Overview

Default storage backend: an Aws::S3::Bucket plus a signing TTL. Constructed with either a bucket name (resolved through HLS.s3_resource at first use) or a pre-built Aws::S3::Bucket (useful in tests or when the host already built one).

HLS::Storage::S3.new(bucket_name: "videos", signing_ttl: 1.hour)
HLS::Storage::S3.new(bucket: my_aws_bucket, signing_ttl: 60)

Constant Summary collapse

DEFAULT_SIGNING_TTL =
3600

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket_name: nil, bucket: nil, s3_resource: nil, signing_ttl: DEFAULT_SIGNING_TTL) ⇒ S3

Returns a new instance of S3.



40
41
42
43
44
45
# File 'lib/hls/storage.rb', line 40

def initialize(bucket_name: nil, bucket: nil, s3_resource: nil, signing_ttl: DEFAULT_SIGNING_TTL)
  @bucket_name = bucket_name
  @bucket = bucket
  @s3_resource = s3_resource
  @signing_ttl = signing_ttl
end

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



38
39
40
# File 'lib/hls/storage.rb', line 38

def bucket_name
  @bucket_name
end

#signing_ttlObject

Returns the value of attribute signing_ttl.



37
38
39
# File 'lib/hls/storage.rb', line 37

def signing_ttl
  @signing_ttl
end

Instance Method Details

#bucketObject

The underlying Aws::S3::Bucket. Resolved lazily so a profile can declare ‘def self.storage = HLS::Storage::S3.new(bucket_name: ENV.fetch(“…”))` without forcing an SDK lookup at class-load time.



55
56
57
58
59
60
61
62
63
# File 'lib/hls/storage.rb', line 55

def bucket
  @bucket ||= begin
    if bucket_name.to_s.empty?
      raise ArgumentError,
        "HLS::Storage::S3 needs either a bucket_name or a pre-built bucket"
    end
    (@s3_resource || HLS.s3_resource).bucket(bucket_name)
  end
end

#object(key) ⇒ Object



47
48
49
# File 'lib/hls/storage.rb', line 47

def object(key)
  bucket.object(key)
end