Module: AwsUpload

Defined in:
lib/aws_upload.rb,
lib/aws_upload/version.rb,
lib/aws_upload/form_helper.rb

Defined Under Namespace

Modules: FormHelper Classes: Uploader

Constant Summary collapse

VERSION =
"0.0.1"
@@aws_access_key_id =
nil
@@aws_secret_access_key =
nil
@@aws_region =
ENV['AWS_REGION']
@@uploaders =
{}

Class Method Summary collapse

Class Method Details

.configure {|_self| ... } ⇒ Object

Module method to configure AwsUpload

Examples

AwsUpload.configure do |config|

config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
config.aws_region = ENV['AWS_REGION']

config.uploader :image do |u|
  u.bucket = 'bucket-name'
  u.key_prefix = 'some-prefix/'
  u.options[:acl] = "public-read"
  u.options[:content_length_range] = 0..1024
  u.options[:success_action_redirect] = "http://url.to/redirected/pass"
end

config.uploader :csv do |u|
  u.bucket = 'bucket-name'
  u.key_prefix = 'some-prefix/'
  u.options[:acl] = "private"
  u.options[:content_length_range] = 0..10240
end

end

Yields:

  • (_self)

Yield Parameters:

  • _self (AwsUpload)

    the object that the method was called on



30
31
32
# File 'lib/aws_upload.rb', line 30

def self.configure
  yield self
end

.uploader(*args, &block) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/aws_upload.rb', line 48

def self.uploader(*args, &block)
  if block_given?
    options = args.extract_options!
    name = args.first || :default
    @@uploaders[name] = Uploader.new().tap{ |u| yield(u) }
  else
    @@uploaders[args.first || :default]
  end
end