Module: Gears::Services

Defined in:
lib/robot_sweatshop/gears/services.rb

Overview

Installs Gears service packages

Class Method Summary collapse

Class Method Details

.dynamically_load_eye(install_path) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/robot_sweatshop/gears/services.rb', line 31

def self.dynamically_load_eye(install_path)
  context = {
    services: services_installed_to(parent_path_of(install_path)),
    install_path: File.expand_path(install_path)
  }
  input = File.read "#{__dir__}/sweatshop_gears.eye.eruby"
  eruby = Erubis::Eruby.new input
  write_and_load eruby.result(context)
end

.expose(from_path:) ⇒ Object



8
9
10
11
12
# File 'lib/robot_sweatshop/gears/services.rb', line 8

def self.expose(from_path:)
  service = File.basename from_path
  dynamically_load_eye from_path
  Announce.success "Loaded #{service} into Eye"
end

.parent_path_of(install_path) ⇒ Object



27
28
29
# File 'lib/robot_sweatshop/gears/services.rb', line 27

def self.parent_path_of(install_path)
  File.expand_path "#{install_path}/.."
end

.services_installed_to(install_path) ⇒ Object



22
23
24
25
# File 'lib/robot_sweatshop/gears/services.rb', line 22

def self.services_installed_to(install_path)
  paths = Dir["#{install_path}/*"].select { |path| File.directory? path }
  paths.map { |path| File.basename path }
end

.write_and_load(eye_config) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/robot_sweatshop/gears/services.rb', line 14

def self.write_and_load(eye_config)
  eye_file = '/tmp/.sweatshop_gears.eye'
  File.write eye_file, eye_config
  puts `eye load #{eye_file}`
  puts `eye stop sweatshop_gears`
  File.delete eye_file
end