Class: GitTools::Submodule

Inherits:
Object
  • Object
show all
Defined in:
lib/gitools/submodules.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yaml = nil) ⇒ Submodule

Initialize

Description

Will load the YAML file given.



86
87
88
# File 'lib/gitools/submodules.rb', line 86

def initialize(yaml = nil)
  @config = load_yaml(yaml) unless yaml.nil?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



76
77
78
# File 'lib/gitools/submodules.rb', line 76

def config
  @config
end

Class Method Details

.add(yaml, name) ⇒ Object

Add

Description

Adds a single submodule to the project.



144
145
146
147
# File 'lib/gitools/submodules.rb', line 144

def self.add(yaml, name)
  git = new(yaml)
  git.add_submodule(name, git.config[name])
end

.add_all(yaml) ⇒ Object

Add All

Description

This will go through the YAML file and do git submodule add for each one.



131
132
133
134
# File 'lib/gitools/submodules.rb', line 131

def self.add_all(yaml)
  git = new(yaml)
  git.config.each { |name, repo| git.add_submodule(name, repo) }
end

.remove_cache(name) ⇒ Object

Remove Cache

Description

This will remove the submodule from git’s cache



157
158
159
# File 'lib/gitools/submodules.rb', line 157

def self.remove_cache(name)
  system("git rm --cache #{directory_to_install(name)}")
end

.setupObject



91
92
93
94
# File 'lib/gitools/submodules.rb', line 91

def self.setup
  system("git submodule init")
  system("git submodule update")
end

.update(name) ⇒ Object

Update

Description

Updates a single submodule in the project



118
119
120
# File 'lib/gitools/submodules.rb', line 118

def self.update(name)
  new.update_submodule(name)
end

.update_all(yaml) ⇒ Object

Update All

Description

This will update all the git submodules specified in the YAML file.



105
106
107
108
# File 'lib/gitools/submodules.rb', line 105

def self.update_all(yaml)
  git = new(yaml)
  git.config.each_key { |name| git.update_submodule(name) }
end

Instance Method Details

#add_submodule(name, repo) ⇒ Object

Add

Description

This can be used by the Class Methods for either adding a single submodule or all of them listed in the YAML file.



185
186
187
# File 'lib/gitools/submodules.rb', line 185

def add_submodule(name, repo)
  message(name) { system("git submodule add #{repo} #{directory_to_install(name)}") }
end

#update_submodule(name) ⇒ Object

Update

Description

This can be used by the Class Methods for either updating a single submodule or all of the submodules listed in the YAML file.



171
172
173
# File 'lib/gitools/submodules.rb', line 171

def update_submodule(name)
  message(name) { system("cd #{directory_to_install(name)} && git remote update && git merge origin/master") }
end