WebRI  WebRI::GitHub

[Validate]
Generated with WebRI Redfish 1.2

GitHub

Public Instance Methods

github_url(path) click to toggle source
# File lib/webri/components/github.rb, line 21
    def github_url(path)
      unless github_url_cache.has_key? path
        github_url_cache[path] = false
        file = RDoc::TopLevel.find_file_named(path)
        if file
          base_url = repository_url(path)
          if base_url
            sha1 = commit_sha1(path)
            if sha1
              relative_url = path_relative_to_repository(path)
              github_url_cache[path] = "#{base_url}#{sha1}#{relative_url}"
            end
          end
        end
      end
      github_url_cache[path]
    end
github_url_cache() click to toggle source
# File lib/webri/components/github.rb, line 40
    def github_url_cache
      @github_url_cache ||= {}
    end
initialize_methods() click to toggle source
# File lib/webri/components/github.rb, line 16
    def initialize_methods
      provision :github_url
    end

Protected Instance Methods

commit_sha1(path) click to toggle source

(Not documented)

# File lib/webri/components/github.rb, line 46
    def commit_sha1(path)
      name = File.basename(path)
      s = in_dir(File.join(path_base, File.dirname(path))) do
        `git log -1 --pretty=format:"commit %H" #{name}`
      end
      m = s.match(/commit\s+(\S+)/)
      m ? m[1] : false
    end
in_dir(dir) click to toggle source

(Not documented)

# File lib/webri/components/github.rb, line 79
    def in_dir(dir)
      pwd = Dir.pwd
      Dir.chdir dir
      return yield
    rescue Exception => e
      return ''
    ensure
      Dir.chdir pwd
    end
path_relative_to_repository(path) click to toggle source

(Not documented)

# File lib/webri/components/github.rb, line 63
    def path_relative_to_repository(path)
      absolute_path = File.join(path_base, path)
      root = path_to_git_dir(File.dirname(absolute_path))
      absolute_path[root.size..absolute_path.size]
    end
path_to_git_dir(path) click to toggle source

(Not documented)

# File lib/webri/components/github.rb, line 69
    def path_to_git_dir(path)
      while !path.empty? && path != '.'
        if (File.exists? File.join(path, '.git')) 
          return path
        end
        path = File.dirname(path)
      end
      ''
    end
repository_url(path) click to toggle source

(Not documented)

# File lib/webri/components/github.rb, line 55
    def repository_url(path)
      s = in_dir(File.join(path_base, File.dirname(path))) do
        `git config --get remote.origin.url`
      end
      m = s.match(%r{github.com[/:](.*)\.git$})
      m ? "http://github.com/#{m[1]}/blob/" : false
    end

Disabled; run with --debug to generate this.