Sha256: 010ad7a1a0e2e679aa8b0a52cc2fc5fb4288d12d41e23e6b5a549571e708ca30

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 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, :authored, :message, :tree,
                  # retrieving commit for a specific sha - "/show/:user/:repo/:sha" adds:
                  :added, :modified, :removed,
                  # extra attributes:
                  :user, :repo

    aliases_for :id => [:sha, :name], :committed => :committed_date, :authored => :authored_date

    def initialize(opts)
      super
      raise "Unable to initialize #{self.class} without id(sha)" unless sha
      @committed = Time.parse(@committed) unless @committed.is_a?(Time)
      @authored = Time.parse(@authored) unless @authored.is_a?(Time)
    end

    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( *args )
        user, repo, branch, sha, path = extract args, :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.3.0 lib/git_hub/commit.rb