Class: Uploader::UploadManager

Inherits:
Object
  • Object
show all
Defined in:
lib/uploader/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, service_override = nil) ⇒ UploadManager

Returns a new instance of UploadManager.



16
17
18
19
20
21
22
23
# File 'lib/uploader/base.rb', line 16

def initialize(config, service_override=nil)
  @config = config   # UploaderConfig
  @service_override = service_override
  @suppressor = Suppressor.new

  set_service!
  connect!
end

Instance Method Details

#close!Object



52
53
54
55
# File 'lib/uploader/base.rb', line 52

def close!
  @service.close!
  @suppressor.close!
end

#connect!Object



44
45
46
# File 'lib/uploader/base.rb', line 44

def connect!
  @service.connect!
end

#get_serviceObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/uploader/base.rb', line 32

def get_service
  service_key = (@service_override || @config.connection).to_sym

  if Service.is_registered?(service_key)
    $stderr.puts "Using service #{service_key}" if @config.verbose?

    return service_key, Service.services[service_key]
  else
    raise UnrecognizedService
  end
end

#set_service!Object



25
26
27
28
29
30
# File 'lib/uploader/base.rb', line 25

def set_service!
  service_name, service_class = get_service
  service_config_hash = @config.send(service_name).merge({:verbose? => @config.verbose?})

  @service = service_class.new(UploaderConfig.new(service_config_hash))
end

#upload(remote_path, contents) ⇒ Object



48
49
50
# File 'lib/uploader/base.rb', line 48

def upload(remote_path, contents)
  @service.upload(remote_path, contents)
end