Class: Contracto::SystemAction
- Inherits:
-
Object
- Object
- Contracto::SystemAction
show all
- Extended by:
- Constants
- Defined in:
- lib/contracto/system_action.rb
Constant Summary
Constants included
from Constants
Constants::CONTRACTO_DIR, Constants::CONTRACTO_TMP_DIR, Constants::CONTRACT_FILENAME, Constants::CONTRACT_PID_FILEPATH, Constants::GEM_DIR, Constants::PORT, Constants::ROOT_DIR, Constants::RUBY_SERVER_DIR
Class Method Summary
collapse
Methods included from Constants
contract_filename, contract_pid_filepath, contracto_dir, contracto_tmp_dir, gem_dir, port, root_dir, ruby_server_dir
Class Method Details
.clone_repo_to_tmp_contracto_dir ⇒ Object
46
47
48
49
|
# File 'lib/contracto/system_action.rb', line 46
def clone_repo_to_tmp_contracto_dir
success = system "git clone -q --depth 1 --single-branch --branch master #{Contracto::Config.repo_url} #{contracto_tmp_dir}"
raise(Contracto::CouldNotDownloadContractError.new(Contracto::Config.repo_url)) unless success
end
|
.create_sample_contract ⇒ Object
15
16
17
18
19
20
21
22
|
# File 'lib/contracto/system_action.rb', line 15
def create_sample_contract
if contract_already_exists?
puts 'contract already exists, creating sample contract skipped'
else
FileUtils.cp sample_contract_path, FileUtils.pwd
puts "created: #{contract_filename}"
end
end
|
.move_repo_files_to_root_dir ⇒ Object
55
56
57
|
# File 'lib/contracto/system_action.rb', line 55
def move_repo_files_to_root_dir
system "mv #{contracto_tmp_dir}/* #{contracto_tmp_dir}/.[^.]* . 2> /dev/null"
end
|
.remove_contracto_dir ⇒ Object
7
8
9
|
# File 'lib/contracto/system_action.rb', line 7
def remove_contracto_dir
FileUtils.rm_rf contracto_dir
end
|
.remove_tmp_contracto_dir ⇒ Object
11
12
13
|
# File 'lib/contracto/system_action.rb', line 11
def remove_tmp_contracto_dir
FileUtils.rm_rf contracto_tmp_dir
end
|
.revert_clone_repo_to_tmp_contracto_dir ⇒ Object
51
52
53
|
# File 'lib/contracto/system_action.rb', line 51
def revert_clone_repo_to_tmp_contracto_dir
remove_tmp_contracto_dir
end
|
.revert_start_server ⇒ Object
41
42
43
44
|
# File 'lib/contracto/system_action.rb', line 41
def revert_start_server
stop_server
rescue StandardError
end
|
.start_server ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/contracto/system_action.rb', line 24
def start_server
raise Contracto::ServerAlreadyRunningError if server_already_running?
system "rackup #{ruby_server_dir}/config.ru -p #{port} -D -P #{contract_pid_filepath}"
system "while ! echo exit | nc localhost #{port} > /dev/null && echo \"waiting for contracto server...\"; do sleep 1; done"
test_request
end
|
.stop_server ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/contracto/system_action.rb', line 33
def stop_server
puts 'killing server...'
Process.kill(15, File.read(contract_pid_filepath).to_i)
puts '...server killed'
rescue Errno::ENOENT
puts 'could not kill server (pidfile not found)'
end
|