Module: Gears::Packages

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

Class Method Summary collapse

Class Method Details

.clone(git_repo, to_path:) ⇒ Object



6
7
8
9
# File 'lib/robot_sweatshop/gears/packages.rb', line 6

def self.clone(git_repo, to_path:)
  return if Dir.exist? to_path
  Git.clone git_repo, File.basename(to_path), path: File.dirname(to_path)
end

.expose(plural_type, from_path:) ⇒ Object



28
29
30
31
# File 'lib/robot_sweatshop/gears/packages.rb', line 28

def self.expose(plural_type, from_path:)
  namespace = Gears.const_get plural_type.capitalize.to_sym
  namespace.send :expose, from_path: from_path
end

.install(package_name, from_path:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/robot_sweatshop/gears/packages.rb', line 33

def self.install(package_name, from_path:)
   =  package_name, from_path
  plural_type = "#{metadata['type']}s"
  install_path = "#{from_path}/#{plural_type}/#{package_name}"
  clone ['repo'], to_path: install_path
  Gears::Dependencies.install from_path: install_path
  expose plural_type, from_path: install_path
  Announce.success "#{package_name} installed"
rescue
  Announce.failure 'Error occurred, rolling back installation'
  FileUtils.rm_rf install_path
end

.install_to(install_path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/robot_sweatshop/gears/packages.rb', line 17

def self.install_to(install_path)
  case ['type']
  when 'script'
    Gears::Scripts.expose from_path: install_path
  when 'service'
    Gears::Services.load from_path: install_path
  else
    fail 'Unknown package type'
  end
end

.metadata_for(package_name, path) ⇒ Object



11
12
13
14
15
# File 'lib/robot_sweatshop/gears/packages.rb', line 11

def self.(package_name, path)
   = "#{path}/#{package_name}.yaml"
  fail "Metadata for '#{package_name}' not found" unless File.exist? 
  YAML.load_file 
end