Class: Front::CLI::Vagrant
- Inherits:
-
Object
- Object
- Front::CLI::Vagrant
- Defined in:
- lib/front/cli/vagrant.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#script ⇒ Object
Returns the value of attribute script.
-
#wait ⇒ Object
Returns the value of attribute wait.
Instance Method Summary collapse
- #capture(cmd) ⇒ Object
- #destroy ⇒ Object
- #get_log_file ⇒ Object
-
#initialize(id, path, script) ⇒ Vagrant
constructor
A new instance of Vagrant.
- #reload ⇒ Object
- #run(cmd) ⇒ Object
- #run2(cmd) ⇒ Object
- #ssh ⇒ Object
- #ssh_config ⇒ Object
- #ssh_port ⇒ Object
- #status ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize(id, path, script) ⇒ Vagrant
Returns a new instance of Vagrant.
11 12 13 14 15 16 |
# File 'lib/front/cli/vagrant.rb', line 11 def initialize(id, path, script) @id = id @path = path @wait = true @script = script end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
6 7 8 |
# File 'lib/front/cli/vagrant.rb', line 6 def id @id end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/front/cli/vagrant.rb', line 7 def path @path end |
#script ⇒ Object
Returns the value of attribute script.
9 10 11 |
# File 'lib/front/cli/vagrant.rb', line 9 def script @script end |
#wait ⇒ Object
Returns the value of attribute wait.
8 9 10 |
# File 'lib/front/cli/vagrant.rb', line 8 def wait @wait end |
Instance Method Details
#capture(cmd) ⇒ Object
92 93 94 95 96 |
# File 'lib/front/cli/vagrant.rb', line 92 def capture(cmd) Dir.chdir(path) do `vagrant #{cmd}` end end |
#destroy ⇒ Object
22 23 24 |
# File 'lib/front/cli/vagrant.rb', line 22 def destroy run('destroy -f') end |
#get_log_file ⇒ Object
57 58 59 |
# File 'lib/front/cli/vagrant.rb', line 57 def get_log_file "#{path}/front.log" end |
#reload ⇒ Object
26 27 28 |
# File 'lib/front/cli/vagrant.rb', line 26 def reload run('reload') end |
#run(cmd) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/front/cli/vagrant.rb', line 61 def run(cmd) cmd = "vagrant #{cmd}" = {} [:chdir] = path if wait pid = Kernel.spawn(cmd, ) Process.wait pid else cmd = "#{cmd} &>> #{get_log_file()} " script.enqueue "cd #{path} && #{cmd}" end end |
#run2(cmd) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/front/cli/vagrant.rb', line 75 def run2(cmd) = {} [:chdir] = path unless wait log_file = "#{path}/front.log" [:out] = log_file [:err] = log_file end pid = Kernel.spawn("vagrant #{cmd}", ) if wait Process.wait pid else Process.detach pid end end |
#ssh ⇒ Object
30 31 32 |
# File 'lib/front/cli/vagrant.rb', line 30 def ssh run('ssh') end |
#ssh_config ⇒ Object
34 35 36 |
# File 'lib/front/cli/vagrant.rb', line 34 def ssh_config capture('ssh-config') end |
#ssh_port ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/front/cli/vagrant.rb', line 38 def ssh_port output = ssh_config() re = /^\s*Port\s*(\d+)$/m matches = output.match(re) return matches[1] end |
#status ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/front/cli/vagrant.rb', line 46 def status output = capture('status') re = /^(\w+\s+\w+ \(\w+\))/m matches = output.match(re) if matches return matches[1] else 'pending' end end |
#up ⇒ Object
18 19 20 |
# File 'lib/front/cli/vagrant.rb', line 18 def up run('up') end |