Class: VagrantGitSyncModule::Core::Workspace

Inherits:
Object
  • Object
show all
Defined in:
lib/core/workspace.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Workspace

Returns a new instance of Workspace.



9
10
11
12
13
14
15
16
17
# File 'lib/core/workspace.rb', line 9

def initialize(env)
  @env = env
  @vagrant_cwd = env[:env].cwd.to_s.strip.chomp('/')
  if File.exist?("#{@vagrant_cwd}/.git") and Workspace.git_installed
    @unsupported_workspace = false
  else
    @unsupported_workspace = true
  end
end

Instance Attribute Details

#unsupported_workspaceObject (readonly)

Returns the value of attribute unsupported_workspace.



7
8
9
# File 'lib/core/workspace.rb', line 7

def unsupported_workspace
  @unsupported_workspace
end

Class Method Details

.git_installedObject



52
53
54
# File 'lib/core/workspace.rb', line 52

def self.git_installed
  not %x(which git).strip.empty?
end

Instance Method Details

#index_clean?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/core/workspace.rb', line 36

def index_clean?
  support_check
  Dir.chdir(@vagrant_cwd) do
    result = %x(git status -s).strip
    return result.empty?
  end
end

#is_master?Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
# File 'lib/core/workspace.rb', line 44

def is_master?
  support_check
  Dir.chdir(@vagrant_cwd) do
    result = %x(git rev-parse --abbrev-ref HEAD).strip
    return result == 'master'
  end
end

#is_online?Boolean

If an internet connection is not available, we want to bail out, and not get in the way

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/core/workspace.rb', line 20

def is_online?
  #Uses a SYN ping vs ICMP to avoid firewall issues.
  #Tries likely ports to determine if computer is up
  tls = Net::Ping::TCP.new(remote_repository, 443, 1)
  http = Net::Ping::TCP.new(remote_repository, 80, 1)
  ssh = Net::Ping::TCP.new(remote_repository, 22, 1)
  tls.ping or http.ping or ssh.ping
end

#updateObject



29
30
31
32
33
34
# File 'lib/core/workspace.rb', line 29

def update
  support_check
  Dir.chdir(@vagrant_cwd) do
    %x(git pull -X theirs -q)
  end
end