Sha256: 9c07e38d19c3867c9f8d113708298a0d65fab145fc08bf1d91c196a82f6e8251

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

module GitHub
  class Commit < Base

    set_resource 'http://github.com/api/v2/yaml/commits', 'commit', 'commits'

    attr_accessor :id, :author, :committer, :parents, :url, :committed_date, :authored_date, :message, :tree,
                  # retrieving commit for a specific sha - "/show/:user/:repo/:sha" adds:
                  :added, :modified, :removed,
                  # extra attributes:
                  :user, :repo

    def initialize opts
      super
      raise "Unable to initialize #{self.class} without id(sha)" unless sha
    end

    alias name id
    alias name= id=
    alias sha id
    alias sha= id=

    class << self
      # Find commits, accepts Hash with keys:
      # :user/:owner/:username:: Github user name
      # :repo/:repository/:project:: Repo name
      # :branch:: Only commits for specific branch - default 'master'
      # :path:: Only commits for specific path
      # :sha/:id:: Only one commit with specific id (sha)
      def find(opts)
        user, repo, branch, sha, path = extract opts, :user, :repo, :branch, :sha, :path 
        repo_given = branch && user && repo
        path = if sha && repo_given
          "/show/#{user}/#{repo}/#{sha}"
        elsif path && repo_given
          "/list/#{user}/#{repo}/#{branch}/#{path}"
        elsif repo_given 
          "/list/#{user}/#{repo}/#{branch}"
        else
          raise "Unable to find #{self.class}(s) for #{opts}"
        end
        instantiate get(path), :user=>user, :repo=>repo
      end

      alias show find
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_hub-0.2.7 lib/git_hub/commit.rb