Class: BetterS3
- Inherits:
-
Object
- Object
- BetterS3
- Defined in:
- lib/better_s3.rb,
lib/better_s3/version.rb,
lib/better_s3/configuration.rb
Defined Under Namespace
Classes: Configuration
Constant Summary collapse
- VERSION =
"2.1.0"
- VERSION_DATE =
"2016-10-12"
Instance Attribute Summary collapse
-
#_payload_body ⇒ Object
Returns the value of attribute _payload_body.
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#file_copied ⇒ Object
Returns the value of attribute file_copied.
-
#s3 ⇒ Object
Returns the value of attribute s3.
Class Method Summary collapse
-
.configuration ⇒ Configuration
Returns the singleton class’s configuration object.
-
.configure(opts = {}) {|configuration| ... } ⇒ Configuration
Allows the user to set configuration options by yielding the configuration block.
- .configured? ⇒ Boolean
- .logger ⇒ Object
Instance Method Summary collapse
-
#delete_local_file_copy(remote_file_name) ⇒ Object
Attempts to delete the local copy of the file, if it exists.
-
#get(remote_file_name) ⇒ String
Returns the body of the payload, retrieved from S3.
-
#initialize ⇒ BetterS3
constructor
A new instance of BetterS3.
-
#put(remote_file_name, str) ⇒ Object
Puts a Ruby hash to s3 as a file.
Constructor Details
#initialize ⇒ BetterS3
Returns a new instance of BetterS3.
38 39 40 |
# File 'lib/better_s3.rb', line 38 def initialize @bucket = BetterS3.configuration.bucket end |
Instance Attribute Details
#_payload_body ⇒ Object
Returns the value of attribute _payload_body.
36 37 38 |
# File 'lib/better_s3.rb', line 36 def _payload_body @_payload_body end |
#bucket ⇒ Object
Returns the value of attribute bucket.
36 37 38 |
# File 'lib/better_s3.rb', line 36 def bucket @bucket end |
#file_copied ⇒ Object
Returns the value of attribute file_copied.
36 37 38 |
# File 'lib/better_s3.rb', line 36 def file_copied @file_copied end |
#s3 ⇒ Object
Returns the value of attribute s3.
36 37 38 |
# File 'lib/better_s3.rb', line 36 def s3 @s3 end |
Class Method Details
.configuration ⇒ Configuration
Returns the singleton class’s configuration object
23 24 25 |
# File 'lib/better_s3.rb', line 23 def configuration @configuration ||= Configuration.new end |
.configure(opts = {}) {|configuration| ... } ⇒ Configuration
Allows the user to set configuration options
by yielding the configuration block
12 13 14 15 16 17 18 |
# File 'lib/better_s3.rb', line 12 def configure(opts = {}, &_block) @configuration = nil if opts.key?(:reset) && opts[:reset] yield(configuration) if block_given? configuration.configure_aws configuration end |
.configured? ⇒ Boolean
27 28 29 |
# File 'lib/better_s3.rb', line 27 def configured? !@configuration.nil? end |
.logger ⇒ Object
31 32 33 |
# File 'lib/better_s3.rb', line 31 def logger LincolnLogger.logger end |
Instance Method Details
#delete_local_file_copy(remote_file_name) ⇒ Object
Attempts to delete the local copy of the file, if it exists
66 67 68 |
# File 'lib/better_s3.rb', line 66 def delete_local_file_copy(remote_file_name) File.delete(full_file_path(remote_file_name)) if File.exist?(full_file_path(remote_file_name)) end |
#get(remote_file_name) ⇒ String
Returns the body of the payload, retrieved from S3
50 51 52 53 |
# File 'lib/better_s3.rb', line 50 def get(remote_file_name) copy_file_from_s3 remote_file_name unless file_copied @_payload_body ||= File.read(full_file_path(remote_file_name)) end |
#put(remote_file_name, str) ⇒ Object
Puts a Ruby hash to s3 as a file
59 60 61 |
# File 'lib/better_s3.rb', line 59 def put(remote_file_name, str) push_object_to_s3 str, remote_file_name end |