Class: BetterS3

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBetterS3

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_bodyObject

Returns the value of attribute _payload_body.



36
37
38
# File 'lib/better_s3.rb', line 36

def _payload_body
  @_payload_body
end

#bucketObject

Returns the value of attribute bucket.



36
37
38
# File 'lib/better_s3.rb', line 36

def bucket
  @bucket
end

#file_copiedObject

Returns the value of attribute file_copied.



36
37
38
# File 'lib/better_s3.rb', line 36

def file_copied
  @file_copied
end

#s3Object

Returns the value of attribute s3.



36
37
38
# File 'lib/better_s3.rb', line 36

def s3
  @s3
end

Class Method Details

.configurationConfiguration

Returns the singleton class’s configuration object

Returns:



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

Parameters:

  • opts (Hash) (defaults to: {})

    an optional hash of options, supported options are ‘reset: true`

  • block (Block)

    an optional configuration block

Yields:

Returns:



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

Returns:

  • (Boolean)


27
28
29
# File 'lib/better_s3.rb', line 27

def configured?
  !@configuration.nil?
end

.loggerObject



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

Parameters:

  • remote_file_name (String)

    the name of the file in the s3 bucket (the s3 object key)



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

Parameters:

  • remote_file_name (String)

    the s3 bucket key

Returns:

  • (String)

    the payload body 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

Parameters:

  • remote_file_name (String)

    the s3 bucket object key where the file should be put

  • str (String)

    the string to be pushed to s3



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