Class: Homeseed::Homeshick

Inherits:
Connection show all
Includes:
Logging
Defined in:
lib/homeseed/homeshick.rb

Constant Summary collapse

EXEC_PATH =
'$HOME/.homesick/repos/homeshick/bin/homeshick'

Instance Attribute Summary

Attributes inherited from Connection

#has_password, #servers, #user

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, global_level=, #logger, logger_for

Methods inherited from Connection

#config_file_path, #exec, #local_exec, #log_exec, #process_hash, #push_bash_file, #push_bash_files, #push_commands, #push_url_commands, #push_yml_commands, #scp_upload, #ssh_exec

Constructor Details

#initialize(params = {}) ⇒ Homeshick

Returns a new instance of Homeshick.



7
8
9
10
# File 'lib/homeseed/homeshick.rb', line 7

def initialize(params={})
  super
  @commands = []
end

Instance Method Details

#fetch_user_config(params = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/homeseed/homeshick.rb', line 33

def fetch_user_config(params={})
  if params[:url]
    response =  HTTParty.get(params[:url])
    raise HTTPartyError unless response.code == 200
    @user_config = YAML.load(response.body)
  else
    file = File.expand_path('.homeseed.yml', ENV['HOME'])
    @user_config = YAML.load_file(file)
  end
end

#install(params = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/homeseed/homeshick.rb', line 12

def install(params={})
  @config_files = Array[config_file_path('homeshick-install.yml')]
  @config_files.unshift(config_file_path('homeshick-prep.yml')) if params[:clean]
  push_commands(files: @config_files)
  fetch_user_config(params)
  user_commands = @user_config[:repos].map do |repo_name,repo_meta|
    "#{EXEC_PATH} clone #{repo_meta[:origin]} --batch && #{EXEC_PATH} symlink #{repo_name} --force"
  end
  push_commands(command: user_commands)
  exec
end

#update(params = {}) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/homeseed/homeshick.rb', line 24

def update(params={})
  fetch_user_config(params)
  user_commands = @user_config[:repos].map do |repo_name,repo_meta|
    "#{EXEC_PATH} pull #{repo_name} --batch && #{EXEC_PATH} symlink #{repo_name} --force"
  end
  push_commands(command: user_commands)
  exec
end