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
- #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.
9 10 11 12 13 14 |
# File 'lib/front/cli/vagrant.rb', line 9 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.
4 5 6 |
# File 'lib/front/cli/vagrant.rb', line 4 def id @id end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/front/cli/vagrant.rb', line 5 def path @path end |
#script ⇒ Object
Returns the value of attribute script.
7 8 9 |
# File 'lib/front/cli/vagrant.rb', line 7 def script @script end |
#wait ⇒ Object
Returns the value of attribute wait.
6 7 8 |
# File 'lib/front/cli/vagrant.rb', line 6 def wait @wait end |
Instance Method Details
#capture(cmd) ⇒ Object
74 75 76 77 78 |
# File 'lib/front/cli/vagrant.rb', line 74 def capture(cmd) Dir.chdir(path) do `vagrant #{cmd}` end end |
#destroy ⇒ Object
20 21 22 |
# File 'lib/front/cli/vagrant.rb', line 20 def destroy run('destroy -f') end |
#get_log_file ⇒ Object
56 57 58 |
# File 'lib/front/cli/vagrant.rb', line 56 def get_log_file "#{path}/front.log" end |
#reload ⇒ Object
24 25 26 |
# File 'lib/front/cli/vagrant.rb', line 24 def reload run('reload') end |
#run(cmd) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/front/cli/vagrant.rb', line 60 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 |
#ssh ⇒ Object
28 29 30 |
# File 'lib/front/cli/vagrant.rb', line 28 def ssh run('ssh') end |
#ssh_config ⇒ Object
32 33 34 |
# File 'lib/front/cli/vagrant.rb', line 32 def ssh_config capture('ssh-config') end |
#ssh_port ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/front/cli/vagrant.rb', line 36 def ssh_port output = ssh_config() re = /^\s*Port\s*(\d+)$/m matches = output.match(re) return matches[1] unless matches.nil? return '2222' end |
#status ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/front/cli/vagrant.rb', line 45 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
16 17 18 |
# File 'lib/front/cli/vagrant.rb', line 16 def up run('up') end |