Class: ActiveStorage::Service::SaasService

Inherits:
ActiveStorage::Service show all
Defined in:
lib/active_storage/service/saas_service.rb

Overview

# config/storage.yml saas:

service: Saas
default_service: qinium
url_expires_in: 300

qinium:

service: Qinium
access_key:
secret_key:
bucket:
put_policy_options:
  expires_in: 3600

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ SaasService

Returns a new instance of SaasService.



19
20
21
22
23
# File 'lib/active_storage/service/saas_service.rb', line 19

def initialize(options)
  super()
  @blob = options.delete(:blob)
  @options = options
end

Instance Attribute Details

#blobObject (readonly)

Returns the value of attribute blob.



17
18
19
# File 'lib/active_storage/service/saas_service.rb', line 17

def blob
  @blob
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/active_storage/service/saas_service.rb', line 17

def options
  @options
end

Instance Method Details

#analyzersObject



70
71
72
73
# File 'lib/active_storage/service/saas_service.rb', line 70

def analyzers
  service_class = service.class
  service_class.respond_to?(:analyzers) ? service_class.analyzers : []
end

#default_serviceObject



79
80
81
# File 'lib/active_storage/service/saas_service.rb', line 79

def default_service
  @default_service ||= ActiveStorage::Blob.services.fetch(@options[:default_service])
end

#form_data_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/active_storage/service/saas_service.rb', line 58

def form_data_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:)
  if service.respond_to?(:form_data_for_direct_upload)
    service.form_data_for_direct_upload key,
                                        expires_in: expires_in,
                                        content_type: content_type,
                                        content_length: content_length,
                                        checksum: checksum
  else
    {}
  end
end

#http_method_for_direct_uploadObject



50
51
52
# File 'lib/active_storage/service/saas_service.rb', line 50

def http_method_for_direct_upload
  service.http_method_for_direct_upload if service.respond_to?(:http_method_for_direct_upload)
end

#http_response_type_for_direct_uploadObject



54
55
56
# File 'lib/active_storage/service/saas_service.rb', line 54

def http_response_type_for_direct_upload
  service.http_response_type_for_direct_upload if service.respond_to?(:http_response_type_for_direct_upload)
end

#name=(_) ⇒ Object



34
35
36
# File 'lib/active_storage/service/saas_service.rb', line 34

def name=(_)
  # do nothing, name should be service.name
end

#respond_to_missing?(method, _include_all) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/active_storage/service/saas_service.rb', line 46

def respond_to_missing?(method, _include_all)
  service.respond_to?(method)
end

#serviceObject



75
76
77
# File 'lib/active_storage/service/saas_service.rb', line 75

def service
  @service ||= (blob && ActiveStorageSaas.service_resolver.call(blob)) || default_service
end