Class: R10K::Module::Git

Inherits:
Base
  • Object
show all
Defined in:
lib/r10k/module/git.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#dirname, #name, #owner, #path, #title

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#accept, #full_path

Constructor Details

#initialize(title, dirname, args) ⇒ Git

Returns a new instance of Git.



19
20
21
22
23
# File 'lib/r10k/module/git.rb', line 19

def initialize(title, dirname, args)
  super
  parse_options(@args)
  @working_dir = R10K::Git::WorkingDir.new(@ref, @remote, @dirname, @name)
end

Instance Attribute Details

#working_dirObject (readonly)

Returns the value of attribute working_dir.



17
18
19
# File 'lib/r10k/module/git.rb', line 17

def working_dir
  @working_dir
end

Class Method Details

.implement?(name, args) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/r10k/module/git.rb', line 8

def self.implement?(name, args)
  args.is_a? Hash and args.has_key?(:git)
rescue
  false
end

Instance Method Details

#propertiesObject



29
30
31
32
33
34
35
# File 'lib/r10k/module/git.rb', line 29

def properties
  {
    :expected => @ref,
    :actual   => (@working_dir.current.sha1 rescue "(unresolvable)"),
    :type     => :git,
  }
end

#statusObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/r10k/module/git.rb', line 49

def status
  if not @working_dir.exist?
    return :absent
  elsif not @working_dir.git?
    return :mismatched
  elsif not @remote == @working_dir.remote
    return :mismatched
  end

  if @working_dir.outdated?
    return :outdated
  end

  return :insync
end

#syncObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/r10k/module/git.rb', line 37

def sync
  case status
  when :absent
    install
  when :mismatched
    uninstall
    install
  when :outdated
    @working_dir.sync
  end
end

#versionObject



25
26
27
# File 'lib/r10k/module/git.rb', line 25

def version
  @ref
end