Module: S3Log
- Defined in:
- lib/s3_log.rb,
lib/s3_log/version.rb,
lib/s3_log/exceptions.rb
Overview
This module is a singleton that implements an append-style S3 file writer.
Defined Under Namespace
Classes: Error, InvalidConfigError, Unconfigured
Constant Summary collapse
- RequiredOptions =
[:access_key_id, :secret_access_key, :bucket]
- VERSION =
'0.0.5'
Class Method Summary collapse
-
.bucket ⇒ Fog::Storage::AWS::Directory, NilClass
Return the singleton’s S3 bucket.
-
.clear_configuration ⇒ NilClass
Clear the singleton logger’s configuration.
-
.configure(options = {}) ⇒ S3Log
Configure the logger so it can be used to write logs.
-
.configured? ⇒ Boolean
Is the logger configured?.
-
.read(path) ⇒ String
Read the given path.
-
.storage ⇒ Fog::Storage::AWS, BilClass
Return the singleton’s S3 Storage object.
-
.write(path, content) ⇒ S3Log
Append the given content to the given S3 path.
Class Method Details
.bucket ⇒ Fog::Storage::AWS::Directory, NilClass
Return the singleton’s S3 bucket
25 26 27 |
# File 'lib/s3_log.rb', line 25 def self.bucket @bucket end |
.clear_configuration ⇒ NilClass
Clear the singleton logger’s configuration
106 107 108 |
# File 'lib/s3_log.rb', line 106 def self.clear_configuration @bucket = @storage = nil end |
.configure(options = {}) ⇒ S3Log
Configure the logger so it can be used to write logs
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/s3_log.rb', line 47 def self.configure( = {}) missing = RequiredOptions - .keys raise InvalidConfigError.new(missing) unless missing.empty? clear_configuration @storage = Fog::Storage::AWS.new( aws_access_key_id: [:access_key_id], aws_secret_access_key: [:secret_access_key] ) @bucket = @storage.directories.create( key: [:bucket], public: false ) self end |
.configured? ⇒ Boolean
Is the logger configured?
33 34 35 |
# File 'lib/s3_log.rb', line 33 def self.configured? storage && bucket end |
.read(path) ⇒ String
Read the given path
93 94 95 96 97 98 99 100 |
# File 'lib/s3_log.rb', line 93 def self.read(path) unless configured? raise Unconfigured end file = bucket.files.get(path) file.nil? ? '' : file.body.to_s end |
.storage ⇒ Fog::Storage::AWS, BilClass
Return the singleton’s S3 Storage object
15 16 17 |
# File 'lib/s3_log.rb', line 15 def self.storage @storage end |
.write(path, content) ⇒ S3Log
Append the given content to the given S3 path
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/s3_log.rb', line 71 def self.write(path, content) unless configured? raise Unconfigured end bucket.files.create( key: path, body: read(path).split("\n").push(content).join("\n"), public: false ) self end |