Module: Fulmar::Domain::Service::Helper::CommonHelper

Defined in:
lib/fulmar/domain/service/helper/common_helper.rb

Overview

Provides the helper methods used in the tasks

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



11
12
13
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 11

def environment
  @environment
end

Instance Method Details

#configFulmar::Domain::Service::ConfigurationService



14
15
16
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 14

def config
  (@_config_service ||= Fulmar::Domain::Service::ConfigurationService.instance.configuration)
end

#download(filename, target = ) ⇒ Object



49
50
51
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 49

def download(filename, target = config[:local_path])
  Fulmar::Infrastructure::Service::CopyService.download(local_shell, config.ssh_user_and_host, filename, target)
end

#error(text) ⇒ Object



79
80
81
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 79

def error(text)
  STDERR.puts(ENV['TERM'] == 'xterm-256color' ? text.light_red : "* Error: #{text}")
end

#file_syncObject



35
36
37
38
39
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 35

def file_sync
  file_sync_model = Fulmar::FileSync.get_class config
  cache_id = "file_sync-#{file_sync_model.config_hash(config)}"
  storage[cache_id] ||= file_sync_model.new(config.clone)
end

#info(text) ⇒ Object



71
72
73
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 71

def info(text)
  puts(ENV['TERM'] == 'xterm-256color' ? text.blue : "* Info: #{text}") if verbose
end

#local_shellFulmar::Shell

Returns:

  • (Fulmar::Shell)


24
25
26
27
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 24

def local_shell
  cache_id = "local_shell-#{config[:local_path]}"
  storage[cache_id] ||= new_shell(config[:local_path])
end

#new_shell(path, hostname = 'localhost') ⇒ Object



53
54
55
56
57
58
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 53

def new_shell(path, hostname = 'localhost')
  shell = Fulmar::Shell.new(path, hostname)
  shell.strict = true
  shell.debug = config[:debug]
  shell
end

#projectFulmar::Domain::Model::Project



19
20
21
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 19

def project
  config.project
end

#remote_shellFulmar::Shell

Returns:

  • (Fulmar::Shell)


30
31
32
33
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 30

def remote_shell
  cache_id = "remote_shell-#{config[:remote_path]}-#{config.ssh_user_and_host}"
  storage[cache_id] ||= new_shell(config[:remote_path], config.ssh_user_and_host)
end

#render_templatesObject



41
42
43
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 41

def render_templates
  (Fulmar::Domain::Service::TemplateRenderingService.new config).render
end

#ssh_configObject



60
61
62
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 60

def ssh_config
  storage['ssh_config'] ||= Fulmar::Infrastructure::Service::SSHConfigService.new config
end

#storageObject



64
65
66
67
68
69
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 64

def storage
  raise 'You need to set an environment and a target first' unless config.ready?
  @storage ||= {}
  @storage[config.environment] ||= {}
  @storage[config.environment][config.target] ||= {}
end

#upload(filename, target = ) ⇒ Object



45
46
47
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 45

def upload(filename, target = config[:remote_path])
  Fulmar::Infrastructure::Service::CopyService.upload(local_shell, filename, config.ssh_user_and_host, target)
end

#warning(text) ⇒ Object



75
76
77
# File 'lib/fulmar/domain/service/helper/common_helper.rb', line 75

def warning(text)
  STDERR.puts(ENV['TERM'] == 'xterm-256color' ? text.magenta : "* Warning: #{text}")
end