Parent

Files

Grit::Submodule

Attributes

id[R]
mode[R]
name[R]

Public Class Methods

config(repo, ref = "master") click to toggle source

The configuration information for the given repo

+repo+ is the Repo
+ref+ is the committish (defaults to 'master')

Returns a Hash of { <path:String> => { ‘url’ => <url:String>, ‘id’ => <id:String> } } Returns {} if no .gitmodules file was found

# File lib/grit/submodule.rb, line 52
def self.config(repo, ref = "master")
  commit = repo.commit(ref)
  blob = commit.tree/'.gitmodules'
  return {} unless blob

  lines = blob.data.gsub(/\r\n?/, "\n" ).split("\n")

  config = {}
  current = nil

  lines.each do |line|
    if line =~ /^\[submodule "(.+)"\]$/
      current = $1
      config[current] = {}
      config[current]['id'] = (commit.tree/current).id
    elsif line =~ /^\t(\w+) = (.+)$/
      config[current][$1] = $2
      config[current]['id'] = (commit.tree/$2).id if $1 == 'path'
    else
      # ignore
    end
  end

  config
end
create(repo, atts) click to toggle source

Create a Submodule containing just the specified attributes

+repo+ is the Repo
+atts+ is a Hash of instance variable data

Returns Grit::Submodule (unbaked)

# File lib/grit/submodule.rb, line 13
def self.create(repo, atts)
  self.allocate.create_initialize(repo, atts)
end

Public Instance Methods

basename() click to toggle source
# File lib/grit/submodule.rb, line 78
def basename
  File.basename(name)
end
create_initialize(repo, atts) click to toggle source

Initializer for Submodule.create

+repo+ is the Repo
+atts+ is a Hash of instance variable data

Returns Grit::Submodule

# File lib/grit/submodule.rb, line 22
def create_initialize(repo, atts)
  @repo = repo
  atts.each do |k, v|
    instance_variable_set("@#{k}".to_sym, v)
  end
  self
end
inspect() click to toggle source

Pretty object inspection

# File lib/grit/submodule.rb, line 83
def inspect
  %{#<Grit::Submodule "#{@id}">}
end
url(ref) click to toggle source

The url of this submodule

+ref+ is the committish that should be used to look up the url

Returns String

# File lib/grit/submodule.rb, line 34
def url(ref)
  config = self.class.config(@repo, ref)

  lookup = config.keys.inject({}) do |acc, key|
    id = config[key]['id']
    acc[id] = config[key]['url']
    acc
  end

  lookup[@id]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.