Class: Star::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/star/configuration.rb

Overview

Provides an object to store global configuration settings.

This class is typically not used directly, but by calling Star.configure, which creates and updates a single instance of Configuration.

An alternative way to set global configuration settings is by storing them in the following environment variables:

  • AWS_ACCESS_KEY_ID to store the ACCESS KEY ID

  • AWS_SECRET_ACCESS_KEY to store the Client Secret for web/device apps

  • AWS_BUCKET to set the name of the S3 bucket

  • STAR_LOCATION to set the path for where to upload the file to

  • STAR_DURATION to set the time (in seconds) for the URL to exist for

  • STAR_REMOTE to store file in the local filesystem and not remotely

In case both methods are used together, Star.configure takes precedence.

Examples:

Set the API access key id/secret access key for AWS S3:

Star.configure do |config|
  config.access_key_id = 'ABCDEFGHIJ1234567890'
  config.secret_access_key = 'ABCDEFGHIJ1234567890'
end

Set the S3 access key id and secret access key:

ENV['AWS_ACCESS_KEY_ID'] = 'ABCDEFGHIJ1234567890'
ENV['AWS_SECRET_ACCESS_KEY'] = 'ABCDEFGHIJ1234567890'

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize the global configuration settings, using the values of the specified following environment variables by default.


54
55
56
57
58
59
60
61
# File 'lib/star/configuration.rb', line 54

def initialize
  @access_key_id = ENV['AWS_ACCESS_KEY_ID']
  @secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
  @bucket = ENV['AWS_BUCKET']
  @location = ENV.fetch('STAR_LOCATION', '/')
  @duration = ENV.fetch('STAR_DURATION', '30').to_i
  @remote = %w(1 t T true TRUE).include? ENV.fetch('STAR_REMOTE', 't')
end

Instance Attribute Details

#access_key_idString

Returns the S3 access key ID.

Returns:

  • (String)

    the S3 access key ID.


34
35
36
# File 'lib/star/configuration.rb', line 34

def access_key_id
  @access_key_id
end

#bucketString

Returns the name of the S3 bucket.

Returns:

  • (String)

    the name of the S3 bucket.


40
41
42
# File 'lib/star/configuration.rb', line 40

def bucket
  @bucket
end

#durationInteger

Returns the number of seconds during which the URL returned by calling #url on a remote file is publicly available.

Returns:

  • (Integer)

    the number of seconds during which the URL returned by calling #url on a remote file is publicly available.


47
48
49
# File 'lib/star/configuration.rb', line 47

def duration
  @duration
end

#locationString

Returns the path where remote files are uploaded to.

Returns:

  • (String)

    the path where remote files are uploaded to.


43
44
45
# File 'lib/star/configuration.rb', line 43

def location
  @location
end

#remoteBooelan

Returns whether to store files remotely or locally.

Returns:

  • (Booelan)

    whether to store files remotely or locally.


50
51
52
# File 'lib/star/configuration.rb', line 50

def remote
  @remote
end

#secret_access_keyString

Returns the S3 secret access key.

Returns:

  • (String)

    the S3 secret access key.


37
38
39
# File 'lib/star/configuration.rb', line 37

def secret_access_key
  @secret_access_key
end