Class: Fulmar::Infrastructure::Service::Transfer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/fulmar/infrastructure/service/transfer/base.rb

Overview

Abstract class for alle transfers, provides common methods

Direct Known Subclasses

Rsync, RsyncWithVersions

Constant Summary collapse

DEFAULT_CONFIG =
{
  debug: false,
  user: '',
  password: '',
  remote_path: nil,
  local_path: '.',
  type: :rsync_with_versions
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Base

Returns a new instance of Base.



21
22
23
24
25
26
27
28
29
# File 'lib/fulmar/infrastructure/service/transfer/base.rb', line 21

def initialize(config)
  @config = DEFAULT_CONFIG.merge(config)

  # Remove trailing slashes
  @config[:local_path] = @config[:local_path].chomp('/') if @config[:local_path]
  @config[:remote_path] = @config[:remote_path].chomp('/') if @config[:remote_path]

  @prepared = false
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



19
20
21
# File 'lib/fulmar/infrastructure/service/transfer/base.rb', line 19

def config
  @config
end

Instance Method Details

#prepareObject



38
39
40
41
42
# File 'lib/fulmar/infrastructure/service/transfer/base.rb', line 38

def prepare
  @local_shell = Fulmar::Infrastructure::Service::ShellService.new @config[:local_path]
  @local_shell.debug = @config[:debug]
  @prepared = true
end

#publishObject



44
45
46
47
# File 'lib/fulmar/infrastructure/service/transfer/base.rb', line 44

def publish
  # Placeholder for consistent api, currently only implemented in rsync_with_versions
  true
end

#test_configObject

Test the supplied config for required parameters



32
33
34
35
36
# File 'lib/fulmar/infrastructure/service/transfer/base.rb', line 32

def test_config
  required = [:host, :remote_path, :local_path]
  required.each { |key| fail "Configuration is missing required setting '#{key}'." if @config.blank? }
  fail ':remote_path must be absolute' if @config[:remote_path][0, 1] != '/'
end