Class: CarrierWave::Uploader::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave-aws.rb

Constant Summary collapse

ACCEPTED_ACL =
%w[
  private
  public-read
  public-read-write
  authenticated-read
  bucket-owner-read
  bucket-owner-full-control
].freeze
ConfigurationError =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.aws_acl=(acl) ⇒ Object



37
38
39
# File 'lib/carrierwave-aws.rb', line 37

def self.aws_acl=(acl)
  @aws_acl = normalized_acl(acl)
end

.aws_signer(value = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/carrierwave-aws.rb', line 51

def self.aws_signer(value = nil)
  self.aws_signer = value if value

  if instance_variable_defined?('@aws_signer')
    @aws_signer
  elsif superclass.respond_to? :aws_signer
    superclass.aws_signer
  end
end

.aws_signer=(signer) ⇒ Object



61
62
63
# File 'lib/carrierwave-aws.rb', line 61

def self.aws_signer=(signer)
  @aws_signer = validated_signer(signer)
end

.normalized_acl(acl) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/carrierwave-aws.rb', line 41

def self.normalized_acl(acl)
  normalized = acl.to_s.downcase.sub('_', '-')

  unless ACCEPTED_ACL.include?(normalized)
    raise ConfigurationError, "Invalid ACL option: #{normalized}"
  end

  normalized
end

.validated_signer(signer) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/carrierwave-aws.rb', line 65

def self.validated_signer(signer)
  unless signer.nil? || signer.instance_of?(Proc) && signer.arity == 2
    raise ConfigurationError,
          'Invalid signer option. Signer proc has to respond to' \
          '`.call(unsigned_url, options)`'
  end

  signer
end

Instance Method Details

#aws_acl=(acl) ⇒ Object



75
76
77
# File 'lib/carrierwave-aws.rb', line 75

def aws_acl=(acl)
  @aws_acl = self.class.normalized_acl(acl)
end

#aws_signerObject



79
80
81
82
83
84
85
# File 'lib/carrierwave-aws.rb', line 79

def aws_signer
  if instance_variable_defined?('@aws_signer')
    @aws_signer
  else
    self.class.aws_signer
  end
end